@getpara/core-sdk 1.4.4 → 1.4.5-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 +1945 -1690
- package/dist/cjs/index.js.br +0 -0
- package/dist/cjs/index.js.gz +0 -0
- package/dist/esm/index.js +1946 -1690
- package/dist/esm/index.js.br +0 -0
- package/dist/esm/index.js.gz +0 -0
- package/package.json +2 -2
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
|
|
@@ -1091,7 +1179,8 @@ if (typeof global !== "undefined") {
|
|
|
1091
1179
|
self.global = self.global || self;
|
|
1092
1180
|
}
|
|
1093
1181
|
var { pki, jsbn } = import_node_forge2.default;
|
|
1094
|
-
var
|
|
1182
|
+
var _supportedWalletTypes, _supportedWalletTypesOpt;
|
|
1183
|
+
var _ParaCore = class _ParaCore {
|
|
1095
1184
|
/**
|
|
1096
1185
|
* Constructs a new `ParaCore` instance.
|
|
1097
1186
|
* @param env - `Environment` to use.
|
|
@@ -1108,8 +1197,8 @@ var ParaCore = class _ParaCore {
|
|
|
1108
1197
|
* 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
1198
|
*/
|
|
1110
1199
|
this.currentWalletIds = {};
|
|
1111
|
-
this
|
|
1112
|
-
this
|
|
1200
|
+
__privateAdd(this, _supportedWalletTypes);
|
|
1201
|
+
__privateAdd(this, _supportedWalletTypesOpt);
|
|
1113
1202
|
this.localStorageGetItem = (key) => {
|
|
1114
1203
|
return this.platformUtils.localStorage.get(key);
|
|
1115
1204
|
};
|
|
@@ -1132,14 +1221,14 @@ var ParaCore = class _ParaCore {
|
|
|
1132
1221
|
* Remove all local storage and prefixed session storage.
|
|
1133
1222
|
* @param {'local' | 'session' | 'secure' | 'all'} type - Type of storage to clear. Defaults to 'all'.
|
|
1134
1223
|
*/
|
|
1135
|
-
this.clearStorage =
|
|
1224
|
+
this.clearStorage = (type = "all") => __async(this, null, function* () {
|
|
1136
1225
|
const isAll = type === "all";
|
|
1137
1226
|
(isAll || type === "local") && this.platformUtils.localStorage.clear(PREFIX);
|
|
1138
1227
|
(isAll || type === "session") && this.platformUtils.sessionStorage.clear(PREFIX);
|
|
1139
1228
|
if ((isAll || type === "secure") && this.platformUtils.secureStorage) {
|
|
1140
1229
|
this.platformUtils.secureStorage.clear(PREFIX);
|
|
1141
1230
|
}
|
|
1142
|
-
};
|
|
1231
|
+
});
|
|
1143
1232
|
this.initializeFromStorage = () => {
|
|
1144
1233
|
this.updateEmailFromStorage();
|
|
1145
1234
|
this.updateCountryCodeFromStorage();
|
|
@@ -1168,18 +1257,16 @@ var ParaCore = class _ParaCore {
|
|
|
1168
1257
|
this.updateEmailFromStorage = () => {
|
|
1169
1258
|
this.email = this.localStorageGetItem(LOCAL_STORAGE_EMAIL) || void 0;
|
|
1170
1259
|
};
|
|
1171
|
-
this.updateWalletsFromStorage =
|
|
1172
|
-
|
|
1260
|
+
this.updateWalletsFromStorage = () => __async(this, null, function* () {
|
|
1261
|
+
var _a;
|
|
1262
|
+
const _currentWalletIds = (_a = this.localStorageGetItem(LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _a : void 0;
|
|
1173
1263
|
const currentWalletIds = [void 0, null, "undefined"].includes(_currentWalletIds) ? {} : (() => {
|
|
1174
1264
|
const fromJson = JSON.parse(_currentWalletIds);
|
|
1175
1265
|
return Array.isArray(fromJson) ? Object.keys(import_user_management_client5.WalletType).reduce((acc, type) => {
|
|
1176
1266
|
const wallet = Object.values(this.wallets).find(
|
|
1177
1267
|
(w) => fromJson.includes(w.id) && WalletSchemeTypeMap[w.scheme][type]
|
|
1178
1268
|
);
|
|
1179
|
-
return {
|
|
1180
|
-
...acc,
|
|
1181
|
-
...wallet && !acc[type] ? { [type]: [wallet.id] } : {}
|
|
1182
|
-
};
|
|
1269
|
+
return __spreadValues(__spreadValues({}, acc), wallet && !acc[type] ? { [type]: [wallet.id] } : {});
|
|
1183
1270
|
}, {}) : fromJson;
|
|
1184
1271
|
})();
|
|
1185
1272
|
this.setCurrentWalletIds(currentWalletIds);
|
|
@@ -1187,34 +1274,25 @@ var ParaCore = class _ParaCore {
|
|
|
1187
1274
|
const _wallets = JSON.parse(stringWallets || "{}");
|
|
1188
1275
|
const stringEd25519Wallets = this.platformUtils.secureStorage ? this.platformUtils.secureStorage.get(LOCAL_STORAGE_ED25519_WALLETS) : this.localStorageGetItem(LOCAL_STORAGE_ED25519_WALLETS);
|
|
1189
1276
|
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
|
-
};
|
|
1277
|
+
const wallets = __spreadValues(__spreadValues({}, Object.keys(_wallets).reduce((res, key) => {
|
|
1278
|
+
return __spreadProps(__spreadValues({}, res), {
|
|
1279
|
+
[key]: migrateWallet(_wallets[key])
|
|
1280
|
+
});
|
|
1281
|
+
}, {})), Object.keys(_ed25519Wallets).reduce((res, key) => {
|
|
1282
|
+
return __spreadValues(__spreadValues({}, res), !res[key] ? { [key]: migrateWallet(_ed25519Wallets[key]) } : {});
|
|
1283
|
+
}, {}));
|
|
1204
1284
|
this.setWallets(wallets);
|
|
1205
|
-
};
|
|
1285
|
+
});
|
|
1206
1286
|
this.updateWalletIdsFromStorage = () => {
|
|
1207
|
-
|
|
1287
|
+
var _a;
|
|
1288
|
+
const _currentWalletIds = (_a = this.localStorageGetItem(LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _a : void 0;
|
|
1208
1289
|
const currentWalletIds = [void 0, null, "undefined"].includes(_currentWalletIds) ? {} : (() => {
|
|
1209
1290
|
const fromJson = JSON.parse(_currentWalletIds);
|
|
1210
1291
|
return Array.isArray(fromJson) ? Object.keys(import_user_management_client5.WalletType).reduce((acc, type) => {
|
|
1211
1292
|
const wallet = Object.values(this.wallets).find(
|
|
1212
1293
|
(w) => fromJson.includes(w.id) && WalletSchemeTypeMap[w.scheme][type]
|
|
1213
1294
|
);
|
|
1214
|
-
return {
|
|
1215
|
-
...acc,
|
|
1216
|
-
...wallet && !acc[type] ? { [type]: [wallet.id] } : {}
|
|
1217
|
-
};
|
|
1295
|
+
return __spreadValues(__spreadValues({}, acc), wallet && !acc[type] ? { [type]: [wallet.id] } : {});
|
|
1218
1296
|
}, {}) : fromJson;
|
|
1219
1297
|
})();
|
|
1220
1298
|
this.setCurrentWalletIds(currentWalletIds);
|
|
@@ -1307,7 +1385,7 @@ var ParaCore = class _ParaCore {
|
|
|
1307
1385
|
this.ctx.mpcComputationClient = initClient2(opts.offloadMPCComputationURL, opts.disableWorkers);
|
|
1308
1386
|
}
|
|
1309
1387
|
try {
|
|
1310
|
-
this
|
|
1388
|
+
__privateSet(this, _supportedWalletTypes, opts.supportedWalletTypes ? (() => {
|
|
1311
1389
|
if (Object.values(opts.supportedWalletTypes).every(
|
|
1312
1390
|
(config) => !!config && typeof config === "object" && config.optional
|
|
1313
1391
|
)) {
|
|
@@ -1316,19 +1394,20 @@ var ParaCore = class _ParaCore {
|
|
|
1316
1394
|
if (!Object.keys(opts.supportedWalletTypes).every((type) => Object.values(import_user_management_client5.WalletType).includes(type))) {
|
|
1317
1395
|
throw new Error("unsupported wallet type");
|
|
1318
1396
|
}
|
|
1319
|
-
this
|
|
1397
|
+
__privateSet(this, _supportedWalletTypesOpt, opts.supportedWalletTypes);
|
|
1320
1398
|
return Object.entries(opts.supportedWalletTypes).reduce((acc, [key, value]) => {
|
|
1399
|
+
var _a;
|
|
1321
1400
|
if (!value) {
|
|
1322
1401
|
return acc;
|
|
1323
1402
|
}
|
|
1324
1403
|
if (key === import_user_management_client5.WalletType.COSMOS && typeof value === "object" && !!value.prefix) {
|
|
1325
1404
|
this.cosmosPrefix = value.prefix;
|
|
1326
1405
|
}
|
|
1327
|
-
return [...acc, { type: key, optional: value === true ? false : value.optional
|
|
1406
|
+
return [...acc, { type: key, optional: value === true ? false : (_a = value.optional) != null ? _a : false }];
|
|
1328
1407
|
}, []);
|
|
1329
|
-
})() : void 0;
|
|
1408
|
+
})() : void 0);
|
|
1330
1409
|
} catch (e) {
|
|
1331
|
-
this
|
|
1410
|
+
__privateSet(this, _supportedWalletTypes, void 0);
|
|
1332
1411
|
}
|
|
1333
1412
|
if (!this.platformUtils.isSyncStorage || opts.useStorageOverrides) {
|
|
1334
1413
|
return;
|
|
@@ -1336,9 +1415,6 @@ var ParaCore = class _ParaCore {
|
|
|
1336
1415
|
this.initializeFromStorage();
|
|
1337
1416
|
setupListeners.bind(this)();
|
|
1338
1417
|
}
|
|
1339
|
-
static {
|
|
1340
|
-
this.version = PARA_CORE_VERSION;
|
|
1341
|
-
}
|
|
1342
1418
|
get isEmail() {
|
|
1343
1419
|
return !!this.email && !this.phone && !this.countryCode && !this.farcasterUsername && !this.telegramUserId;
|
|
1344
1420
|
}
|
|
@@ -1353,9 +1429,10 @@ var ParaCore = class _ParaCore {
|
|
|
1353
1429
|
}
|
|
1354
1430
|
get currentWalletIdsArray() {
|
|
1355
1431
|
return this.supportedWalletTypes.reduce((acc, { type }) => {
|
|
1432
|
+
var _a;
|
|
1356
1433
|
return [
|
|
1357
1434
|
...acc,
|
|
1358
|
-
...(this.currentWalletIds[type]
|
|
1435
|
+
...((_a = this.currentWalletIds[type]) != null ? _a : []).map((id) => {
|
|
1359
1436
|
return [id, type];
|
|
1360
1437
|
})
|
|
1361
1438
|
];
|
|
@@ -1368,19 +1445,17 @@ var ParaCore = class _ParaCore {
|
|
|
1368
1445
|
* A map of pre-generated wallet identifiers that can be claimed in the current instance.
|
|
1369
1446
|
*/
|
|
1370
1447
|
get pregenIds() {
|
|
1371
|
-
return {
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
[wallet.pregenIdentifierType]: [
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
}, {})
|
|
1383
|
-
};
|
|
1448
|
+
return __spreadValues({}, Object.values(this.wallets).filter((wallet) => !this.userId || this.isPregenWalletClaimable(wallet)).reduce((acc, wallet) => {
|
|
1449
|
+
var _a, _b;
|
|
1450
|
+
if (((_a = acc[wallet.pregenIdentifierType]) != null ? _a : []).includes(wallet.pregenIdentifier)) {
|
|
1451
|
+
return acc;
|
|
1452
|
+
}
|
|
1453
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
1454
|
+
[wallet.pregenIdentifierType]: [
|
|
1455
|
+
.../* @__PURE__ */ new Set([...(_b = acc[wallet.pregenIdentifierType]) != null ? _b : [], wallet.pregenIdentifier])
|
|
1456
|
+
]
|
|
1457
|
+
});
|
|
1458
|
+
}, {}));
|
|
1384
1459
|
}
|
|
1385
1460
|
/**
|
|
1386
1461
|
* Whether the instance has multiple wallets connected.
|
|
@@ -1388,14 +1463,13 @@ var ParaCore = class _ParaCore {
|
|
|
1388
1463
|
get isMultiWallet() {
|
|
1389
1464
|
return this.currentWalletIdsArray.length > 1;
|
|
1390
1465
|
}
|
|
1391
|
-
#supportedWalletTypes;
|
|
1392
|
-
#supportedWalletTypesOpt;
|
|
1393
1466
|
get supportedWalletTypes() {
|
|
1394
|
-
|
|
1467
|
+
var _a;
|
|
1468
|
+
return (_a = __privateGet(this, _supportedWalletTypes)) != null ? _a : [];
|
|
1395
1469
|
}
|
|
1396
1470
|
get isWalletTypeEnabled() {
|
|
1397
1471
|
return this.supportedWalletTypes.reduce((acc, { type }) => {
|
|
1398
|
-
return {
|
|
1472
|
+
return __spreadProps(__spreadValues({}, acc), { [type]: true });
|
|
1399
1473
|
}, {});
|
|
1400
1474
|
}
|
|
1401
1475
|
convertBigInt(bigInt) {
|
|
@@ -1424,12 +1498,14 @@ var ParaCore = class _ParaCore {
|
|
|
1424
1498
|
};
|
|
1425
1499
|
}
|
|
1426
1500
|
isPortal(envOverride) {
|
|
1501
|
+
var _a;
|
|
1427
1502
|
if (typeof window === "undefined") return false;
|
|
1428
|
-
return !!window.location
|
|
1503
|
+
return !!((_a = window.location) == null ? void 0 : _a.host) && getPortalBaseURL(envOverride ? { env: envOverride } : this.ctx).includes(window.location.host);
|
|
1429
1504
|
}
|
|
1430
1505
|
isParaConnect() {
|
|
1506
|
+
var _a;
|
|
1431
1507
|
if (typeof window === "undefined") return false;
|
|
1432
|
-
return !!window.location
|
|
1508
|
+
return !!((_a = window.location) == null ? void 0 : _a.host) && getParaConnectBaseUrl(this.ctx).includes(window.location.host);
|
|
1433
1509
|
}
|
|
1434
1510
|
requireApiKey() {
|
|
1435
1511
|
if (!this.ctx.apiKey) {
|
|
@@ -1440,19 +1516,20 @@ var ParaCore = class _ParaCore {
|
|
|
1440
1516
|
}
|
|
1441
1517
|
}
|
|
1442
1518
|
isWalletSupported(wallet) {
|
|
1443
|
-
|
|
1519
|
+
var _a, _b;
|
|
1520
|
+
return !__privateGet(this, _supportedWalletTypes) || isWalletSupported((_b = (_a = this.supportedWalletTypes) == null ? void 0 : _a.map(({ type }) => type)) != null ? _b : [], wallet);
|
|
1444
1521
|
}
|
|
1445
1522
|
isWalletOwned(wallet) {
|
|
1446
|
-
return this.isWalletSupported(wallet) && !wallet
|
|
1523
|
+
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
1524
|
}
|
|
1448
1525
|
isPregenWalletUnclaimed(wallet) {
|
|
1449
|
-
return this.isWalletSupported(wallet) && (!wallet
|
|
1526
|
+
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
1527
|
}
|
|
1451
1528
|
isPregenWalletClaimable(wallet) {
|
|
1452
|
-
return this.isWalletSupported(wallet) && this.isPregenWalletUnclaimed(wallet) && (!["EMAIL", "PHONE", "TELEGRAM"].includes(wallet
|
|
1453
|
-
wallet
|
|
1454
|
-
wallet
|
|
1455
|
-
wallet
|
|
1529
|
+
return this.isWalletSupported(wallet) && this.isPregenWalletUnclaimed(wallet) && (!["EMAIL", "PHONE", "TELEGRAM"].includes(wallet == null ? void 0 : wallet.pregenIdentifierType) || isPregenIdentifierMatch(
|
|
1530
|
+
(wallet == null ? void 0 : wallet.pregenIdentifierType) === "EMAIL" ? this.email : (wallet == null ? void 0 : wallet.pregenIdentifierType) === "TELEGRAM" ? this.telegramUserId : this.getPhoneNumber(),
|
|
1531
|
+
wallet == null ? void 0 : wallet.pregenIdentifier,
|
|
1532
|
+
wallet == null ? void 0 : wallet.pregenIdentifierType
|
|
1456
1533
|
));
|
|
1457
1534
|
}
|
|
1458
1535
|
isWalletUsable(walletId, { type: types, scheme: schemes, forbidPregen = false } = {}, throwError = false) {
|
|
@@ -1463,15 +1540,18 @@ var ParaCore = class _ParaCore {
|
|
|
1463
1540
|
const wallet = this.wallets[walletId];
|
|
1464
1541
|
const [isUnclaimed, isOwned] = [this.isPregenWalletUnclaimed(wallet), this.isWalletOwned(wallet)];
|
|
1465
1542
|
if (forbidPregen && isUnclaimed) {
|
|
1466
|
-
error = `pre-generated wallet with id ${wallet
|
|
1543
|
+
error = `pre-generated wallet with id ${wallet == null ? void 0 : wallet.id} cannot be selected`;
|
|
1467
1544
|
} else if (!isOwned && !isUnclaimed) {
|
|
1468
|
-
error = `wallet with id ${wallet
|
|
1545
|
+
error = `wallet with id ${wallet == null ? void 0 : wallet.id} is not owned by the current user`;
|
|
1469
1546
|
} else if (!this.isWalletSupported(wallet)) {
|
|
1470
|
-
error = `wallet with id ${wallet
|
|
1471
|
-
} else if (types && (!getEquivalentTypes(types).includes(wallet
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1547
|
+
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(", ")}`;
|
|
1548
|
+
} else if (types && (!getEquivalentTypes(types).includes(wallet == null ? void 0 : wallet.type) || isOwned && !types.some((type) => {
|
|
1549
|
+
var _a, _b;
|
|
1550
|
+
return (_b = (_a = this.currentWalletIds) == null ? void 0 : _a[type]) == null ? void 0 : _b.includes(walletId);
|
|
1551
|
+
}))) {
|
|
1552
|
+
error = `wallet with id ${wallet == null ? void 0 : wallet.id} and type ${wallet == null ? void 0 : wallet.type} cannot be selected`;
|
|
1553
|
+
} else if (schemes && !schemes.includes(wallet == null ? void 0 : wallet.scheme)) {
|
|
1554
|
+
error = `wallet with id ${wallet == null ? void 0 : wallet.id} and scheme ${wallet == null ? void 0 : wallet.scheme} cannot be selected`;
|
|
1475
1555
|
}
|
|
1476
1556
|
}
|
|
1477
1557
|
if (error) {
|
|
@@ -1491,6 +1571,7 @@ var ParaCore = class _ParaCore {
|
|
|
1491
1571
|
* @returns the formatted address
|
|
1492
1572
|
*/
|
|
1493
1573
|
getDisplayAddress(walletId, options = {}) {
|
|
1574
|
+
var _a;
|
|
1494
1575
|
if (this.externalWallets[walletId]) {
|
|
1495
1576
|
const wallet2 = this.externalWallets[walletId];
|
|
1496
1577
|
return options.truncate ? truncateAddress(wallet2.address, wallet2.type, { prefix: this.cosmosPrefix }) : wallet2.address;
|
|
@@ -1502,7 +1583,7 @@ var ParaCore = class _ParaCore {
|
|
|
1502
1583
|
let str;
|
|
1503
1584
|
switch (wallet.type) {
|
|
1504
1585
|
case import_user_management_client5.WalletType.COSMOS:
|
|
1505
|
-
str = getCosmosAddress(wallet.publicKey, this.cosmosPrefix
|
|
1586
|
+
str = getCosmosAddress(wallet.publicKey, (_a = this.cosmosPrefix) != null ? _a : "cosmos");
|
|
1506
1587
|
break;
|
|
1507
1588
|
default:
|
|
1508
1589
|
str = wallet.address;
|
|
@@ -1528,89 +1609,87 @@ var ParaCore = class _ParaCore {
|
|
|
1528
1609
|
return this.wallets;
|
|
1529
1610
|
}
|
|
1530
1611
|
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
|
-
|
|
1612
|
+
var _a, _b, _c;
|
|
1613
|
+
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;
|
|
1614
|
+
}
|
|
1615
|
+
constructPortalUrl(_0) {
|
|
1616
|
+
return __async(this, arguments, function* (type, opts = {}) {
|
|
1617
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
1618
|
+
const base = type === "onRamp" ? getPortalBaseURL(this.ctx) : yield this.getPortalURL(opts.partnerId);
|
|
1619
|
+
let path;
|
|
1620
|
+
switch (type) {
|
|
1621
|
+
case "createPassword": {
|
|
1622
|
+
path = `/web/users/${this.userId}/passwords/${opts.pathId}`;
|
|
1623
|
+
break;
|
|
1624
|
+
}
|
|
1625
|
+
case "createAuth": {
|
|
1626
|
+
path = `/web/users/${this.userId}/biometrics/${opts.pathId}`;
|
|
1627
|
+
break;
|
|
1628
|
+
}
|
|
1629
|
+
case "loginPassword": {
|
|
1630
|
+
path = "/web/passwords/login";
|
|
1631
|
+
break;
|
|
1632
|
+
}
|
|
1633
|
+
case "loginAuth": {
|
|
1634
|
+
path = "/web/biometrics/login";
|
|
1635
|
+
break;
|
|
1636
|
+
}
|
|
1637
|
+
case "txReview": {
|
|
1638
|
+
path = `/web/users/${this.userId}/transaction-review/${opts.pathId}`;
|
|
1639
|
+
break;
|
|
1640
|
+
}
|
|
1641
|
+
case "onRamp": {
|
|
1642
|
+
path = `/web/users/${this.userId}/on-ramp-transaction/${opts.pathId}`;
|
|
1643
|
+
break;
|
|
1644
|
+
}
|
|
1645
|
+
default: {
|
|
1646
|
+
throw new Error(`invalid URL type ${type}`);
|
|
1647
|
+
}
|
|
1563
1648
|
}
|
|
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 ? {
|
|
1649
|
+
const [isCreate, isLogin, isOnRamp] = [
|
|
1650
|
+
["createAuth", "createPassword"].includes(type),
|
|
1651
|
+
["loginAuth", "loginPassword"].includes(type),
|
|
1652
|
+
type === "onRamp"
|
|
1653
|
+
];
|
|
1654
|
+
const partner = opts.partnerId ? (_a = (yield this.ctx.client.getPartner(opts.partnerId)).data) == null ? void 0 : _a.partner : void 0;
|
|
1655
|
+
const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
1656
|
+
apiKey: this.ctx.apiKey,
|
|
1657
|
+
partnerId: opts.partnerId,
|
|
1658
|
+
portalFont: ((_b = opts.theme) == null ? void 0 : _b.font) || (partner == null ? void 0 : partner.font) || ((_c = this.portalTheme) == null ? void 0 : _c.font),
|
|
1659
|
+
portalBorderRadius: ((_d = opts.theme) == null ? void 0 : _d.borderRadius) || ((_e = this.portalTheme) == null ? void 0 : _e.borderRadius),
|
|
1660
|
+
portalThemeMode: ((_f = opts.theme) == null ? void 0 : _f.mode) || (partner == null ? void 0 : partner.themeMode) || ((_g = this.portalTheme) == null ? void 0 : _g.mode),
|
|
1661
|
+
portalAccentColor: ((_h = opts.theme) == null ? void 0 : _h.accentColor) || (partner == null ? void 0 : partner.accentColor) || ((_i = this.portalTheme) == null ? void 0 : _i.accentColor),
|
|
1662
|
+
portalForegroundColor: ((_j = opts.theme) == null ? void 0 : _j.foregroundColor) || (partner == null ? void 0 : partner.foregroundColor) || ((_k = this.portalTheme) == null ? void 0 : _k.foregroundColor),
|
|
1663
|
+
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),
|
|
1664
|
+
portalPrimaryButtonColor: this.portalPrimaryButtonColor,
|
|
1665
|
+
portalTextColor: this.portalTextColor,
|
|
1666
|
+
portalPrimaryButtonTextColor: this.portalPrimaryButtonTextColor,
|
|
1667
|
+
isForNewDevice: opts.isForNewDevice ? opts.isForNewDevice.toString() : void 0,
|
|
1668
|
+
supportedWalletTypes: __privateGet(this, _supportedWalletTypesOpt) ? JSON.stringify(__privateGet(this, _supportedWalletTypesOpt)) : void 0
|
|
1669
|
+
}, 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
1670
|
encryptionKey: opts.loginEncryptionPublicKey,
|
|
1594
1671
|
newDeviceSessionLookupId: opts.newDeviceSessionId,
|
|
1595
1672
|
newDeviceEncryptionKey: opts.newDeviceEncryptionKey,
|
|
1596
1673
|
pregenIds: JSON.stringify(this.pregenIds),
|
|
1597
1674
|
displayName: opts.displayName,
|
|
1598
1675
|
pfpUrl: opts.pfpUrl
|
|
1599
|
-
} : {},
|
|
1600
|
-
|
|
1601
|
-
};
|
|
1602
|
-
return constructUrl({ base, path, params });
|
|
1676
|
+
} : {}), opts.params || {});
|
|
1677
|
+
return constructUrl({ base, path, params });
|
|
1678
|
+
});
|
|
1603
1679
|
}
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1680
|
+
touchSession(regenerate = false) {
|
|
1681
|
+
return __async(this, null, function* () {
|
|
1682
|
+
const res = yield this.ctx.client.touchSession(regenerate);
|
|
1683
|
+
this.setSupportedWalletTypes(res.data.supportedWalletTypes, res.data.cosmosPrefix);
|
|
1684
|
+
return res;
|
|
1685
|
+
});
|
|
1608
1686
|
}
|
|
1609
1687
|
setSupportedWalletTypes(supportedWalletTypes, cosmosPrefix) {
|
|
1610
|
-
if (supportedWalletTypes && !this
|
|
1611
|
-
this
|
|
1688
|
+
if (supportedWalletTypes && !__privateGet(this, _supportedWalletTypes)) {
|
|
1689
|
+
__privateSet(this, _supportedWalletTypes, supportedWalletTypes);
|
|
1612
1690
|
Object.keys(this.currentWalletIds).forEach((type) => {
|
|
1613
|
-
|
|
1691
|
+
var _a;
|
|
1692
|
+
if (!((_a = __privateGet(this, _supportedWalletTypes)) == null ? void 0 : _a.some(({ type: supportedType }) => supportedType === type))) {
|
|
1614
1693
|
delete this.currentWalletIds[type];
|
|
1615
1694
|
}
|
|
1616
1695
|
});
|
|
@@ -1646,166 +1725,181 @@ var ParaCore = class _ParaCore {
|
|
|
1646
1725
|
*
|
|
1647
1726
|
* Init only needs to be called for storage that is async.
|
|
1648
1727
|
*/
|
|
1649
|
-
|
|
1650
|
-
this
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1728
|
+
init() {
|
|
1729
|
+
return __async(this, null, function* () {
|
|
1730
|
+
var _a;
|
|
1731
|
+
this.email = (yield this.localStorageGetItem(LOCAL_STORAGE_EMAIL)) || void 0;
|
|
1732
|
+
this.countryCode = (yield this.localStorageGetItem(LOCAL_STORAGE_COUNTRY_CODE)) || void 0;
|
|
1733
|
+
this.phone = (yield this.localStorageGetItem(LOCAL_STORAGE_PHONE)) || void 0;
|
|
1734
|
+
this.userId = (yield this.localStorageGetItem(LOCAL_STORAGE_USER_ID)) || void 0;
|
|
1735
|
+
this.telegramUserId = (yield this.localStorageGetItem(LOCAL_STORAGE_TELEGRAM_USER_ID)) || void 0;
|
|
1736
|
+
const stringWallets = this.platformUtils.secureStorage ? yield this.platformUtils.secureStorage.get(LOCAL_STORAGE_WALLETS) : yield this.localStorageGetItem(LOCAL_STORAGE_WALLETS);
|
|
1737
|
+
const _wallets = JSON.parse(stringWallets || "{}");
|
|
1738
|
+
const stringEd25519Wallets = this.platformUtils.secureStorage ? yield this.platformUtils.secureStorage.get(LOCAL_STORAGE_ED25519_WALLETS) : yield this.localStorageGetItem(LOCAL_STORAGE_ED25519_WALLETS);
|
|
1739
|
+
const _ed25519Wallets = JSON.parse(stringEd25519Wallets || "{}");
|
|
1740
|
+
const wallets = __spreadValues(__spreadValues({}, Object.keys(_wallets).reduce((res, key) => {
|
|
1741
|
+
return __spreadProps(__spreadValues({}, res), {
|
|
1663
1742
|
[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
|
-
|
|
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();
|
|
1743
|
+
});
|
|
1744
|
+
}, {})), Object.keys(_ed25519Wallets).reduce((res, key) => {
|
|
1745
|
+
return __spreadValues(__spreadValues({}, res), !res[key] ? { [key]: migrateWallet(_ed25519Wallets[key]) } : {});
|
|
1746
|
+
}, {}));
|
|
1747
|
+
yield this.setWallets(wallets);
|
|
1748
|
+
const _currentWalletIds = (_a = yield this.localStorageGetItem(LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _a : void 0;
|
|
1749
|
+
const currentWalletIds = [void 0, null, "undefined", "null"].includes(_currentWalletIds) ? {} : (() => {
|
|
1750
|
+
const fromJson = JSON.parse(_currentWalletIds);
|
|
1751
|
+
return Array.isArray(fromJson) ? Object.keys(import_user_management_client5.WalletType).reduce((acc, type) => {
|
|
1752
|
+
const wallet = Object.values(this.wallets).find(
|
|
1753
|
+
(w) => fromJson.includes(w.id) && WalletSchemeTypeMap[w.scheme][type]
|
|
1754
|
+
);
|
|
1755
|
+
return __spreadValues(__spreadValues({}, acc), wallet && !acc[type] ? { [type]: [wallet.id] } : {});
|
|
1756
|
+
}, {}) : fromJson;
|
|
1757
|
+
})();
|
|
1758
|
+
yield this.setCurrentWalletIds(currentWalletIds);
|
|
1759
|
+
this.sessionCookie = (yield this.localStorageGetItem(LOCAL_STORAGE_SESSION_COOKIE)) || (yield this.sessionStorageGetItem(LOCAL_STORAGE_SESSION_COOKIE)) || void 0;
|
|
1760
|
+
if (Object.values(this.wallets).filter((w) => this.isWalletOwned(w)).length > 0 && this.currentWalletIdsArray.length === 0) {
|
|
1761
|
+
this.findWalletId(void 0, { forbidPregen: true });
|
|
1762
|
+
}
|
|
1763
|
+
const loginEncryptionKey = yield this.sessionStorageGetItem(SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR);
|
|
1764
|
+
if (loginEncryptionKey && loginEncryptionKey !== "undefined") {
|
|
1765
|
+
this.loginEncryptionKeyPair = this.convertEncryptionKeyPair(JSON.parse(loginEncryptionKey));
|
|
1766
|
+
}
|
|
1767
|
+
const stringExternalWallets = yield this.localStorageGetItem(LOCAL_STORAGE_EXTERNAL_WALLETS);
|
|
1768
|
+
const _externalWallets = JSON.parse(stringExternalWallets || "{}");
|
|
1769
|
+
yield this.setExternalWallets(_externalWallets);
|
|
1770
|
+
const _currentExternalWalletAddresses = (yield this.localStorageGetItem(LOCAL_STORAGE_CURRENT_EXTERNAL_WALLET_ADDRESSES)) || void 0;
|
|
1771
|
+
this.currentExternalWalletAddresses = _currentExternalWalletAddresses ? JSON.parse(_currentExternalWalletAddresses) : void 0;
|
|
1772
|
+
setupListeners.bind(this)();
|
|
1773
|
+
yield this.touchSession();
|
|
1774
|
+
});
|
|
1703
1775
|
}
|
|
1704
1776
|
/**
|
|
1705
1777
|
* Sets the email associated with the `ParaCore` instance.
|
|
1706
1778
|
* @param email - Email to set.
|
|
1707
1779
|
*/
|
|
1708
|
-
|
|
1709
|
-
this
|
|
1710
|
-
|
|
1780
|
+
setEmail(email) {
|
|
1781
|
+
return __async(this, null, function* () {
|
|
1782
|
+
this.email = email;
|
|
1783
|
+
yield this.localStorageSetItem(LOCAL_STORAGE_EMAIL, email);
|
|
1784
|
+
});
|
|
1711
1785
|
}
|
|
1712
1786
|
/**
|
|
1713
1787
|
* Sets the Telegram user ID associated with the `ParaCore` instance.
|
|
1714
1788
|
* @param telegramUserId - Telegram user ID to set.
|
|
1715
1789
|
*/
|
|
1716
|
-
|
|
1717
|
-
this
|
|
1718
|
-
|
|
1790
|
+
setTelegramUserId(telegramUserId) {
|
|
1791
|
+
return __async(this, null, function* () {
|
|
1792
|
+
this.telegramUserId = telegramUserId;
|
|
1793
|
+
yield this.localStorageSetItem(LOCAL_STORAGE_TELEGRAM_USER_ID, telegramUserId);
|
|
1794
|
+
});
|
|
1719
1795
|
}
|
|
1720
1796
|
/**
|
|
1721
1797
|
* Sets the phone number associated with the `ParaCore` instance.
|
|
1722
1798
|
* @param phone - Phone number to set.
|
|
1723
1799
|
* @param countryCode - Country Code to set.
|
|
1724
1800
|
*/
|
|
1725
|
-
|
|
1726
|
-
this
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1801
|
+
setPhoneNumber(phone, countryCode) {
|
|
1802
|
+
return __async(this, null, function* () {
|
|
1803
|
+
this.phone = phone;
|
|
1804
|
+
this.countryCode = countryCode;
|
|
1805
|
+
yield this.localStorageSetItem(LOCAL_STORAGE_PHONE, phone);
|
|
1806
|
+
yield this.localStorageSetItem(LOCAL_STORAGE_COUNTRY_CODE, countryCode);
|
|
1807
|
+
});
|
|
1730
1808
|
}
|
|
1731
1809
|
/**
|
|
1732
1810
|
* Sets the farcaster username associated with the `ParaCore` instance.
|
|
1733
1811
|
* @param farcasterUsername - Farcaster Username to set.
|
|
1734
1812
|
*/
|
|
1735
|
-
|
|
1736
|
-
this
|
|
1737
|
-
|
|
1813
|
+
setFarcasterUsername(farcasterUsername) {
|
|
1814
|
+
return __async(this, null, function* () {
|
|
1815
|
+
this.farcasterUsername = farcasterUsername;
|
|
1816
|
+
yield this.localStorageSetItem(LOCAL_STORAGE_FARCASTER_USERNAME, farcasterUsername);
|
|
1817
|
+
});
|
|
1738
1818
|
}
|
|
1739
1819
|
/**
|
|
1740
1820
|
* Sets the external wallet address and type associated with the `ParaCore` instance.
|
|
1741
1821
|
* @param externalAddress - External wallet address to set.
|
|
1742
1822
|
* @param externalType - Type of external wallet to set.
|
|
1743
1823
|
*/
|
|
1744
|
-
|
|
1745
|
-
this
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1824
|
+
setExternalWallet(_0) {
|
|
1825
|
+
return __async(this, arguments, function* ({ address, type, provider, addressBech32 }) {
|
|
1826
|
+
this.externalWallets = {
|
|
1827
|
+
[address]: {
|
|
1828
|
+
id: address,
|
|
1829
|
+
address: addressBech32 != null ? addressBech32 : address,
|
|
1830
|
+
type,
|
|
1831
|
+
name: provider,
|
|
1832
|
+
isExternal: true,
|
|
1833
|
+
signer: ""
|
|
1834
|
+
}
|
|
1835
|
+
};
|
|
1836
|
+
this.currentExternalWalletAddresses = [address];
|
|
1837
|
+
this.setCurrentExternalWalletAddresses(this.currentExternalWalletAddresses);
|
|
1838
|
+
this.setExternalWallets(this.externalWallets);
|
|
1839
|
+
dispatchEvent(ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, null);
|
|
1840
|
+
});
|
|
1759
1841
|
}
|
|
1760
1842
|
/**
|
|
1761
1843
|
* Sets the user id associated with the `ParaCore` instance.
|
|
1762
1844
|
* @param userId - User id to set.
|
|
1763
1845
|
*/
|
|
1764
|
-
|
|
1765
|
-
this
|
|
1766
|
-
|
|
1846
|
+
setUserId(userId) {
|
|
1847
|
+
return __async(this, null, function* () {
|
|
1848
|
+
this.userId = userId;
|
|
1849
|
+
yield this.localStorageSetItem(LOCAL_STORAGE_USER_ID, userId);
|
|
1850
|
+
});
|
|
1767
1851
|
}
|
|
1768
1852
|
/**
|
|
1769
1853
|
* Sets the wallets associated with the `ParaCore` instance.
|
|
1770
1854
|
* @param wallets - Wallets to set.
|
|
1771
1855
|
*/
|
|
1772
|
-
|
|
1773
|
-
this
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1856
|
+
setWallets(wallets) {
|
|
1857
|
+
return __async(this, null, function* () {
|
|
1858
|
+
this.wallets = wallets;
|
|
1859
|
+
if (this.platformUtils.secureStorage) {
|
|
1860
|
+
yield this.platformUtils.secureStorage.set(LOCAL_STORAGE_WALLETS, JSON.stringify(wallets));
|
|
1861
|
+
return;
|
|
1862
|
+
}
|
|
1863
|
+
yield this.localStorageSetItem(LOCAL_STORAGE_WALLETS, JSON.stringify(wallets));
|
|
1864
|
+
});
|
|
1779
1865
|
}
|
|
1780
1866
|
/**
|
|
1781
1867
|
* Sets the external wallets associated with the `ParaCore` instance.
|
|
1782
1868
|
* @param externalWallets - External wallets to set.
|
|
1783
1869
|
*/
|
|
1784
|
-
|
|
1785
|
-
this
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1870
|
+
setExternalWallets(externalWallets) {
|
|
1871
|
+
return __async(this, null, function* () {
|
|
1872
|
+
this.externalWallets = externalWallets;
|
|
1873
|
+
yield this.localStorageSetItem(LOCAL_STORAGE_EXTERNAL_WALLETS, JSON.stringify(externalWallets));
|
|
1874
|
+
});
|
|
1875
|
+
}
|
|
1876
|
+
setCurrentExternalWalletAddresses(currentExternalWalletAddresses) {
|
|
1877
|
+
return __async(this, null, function* () {
|
|
1878
|
+
this.currentExternalWalletAddresses = currentExternalWalletAddresses;
|
|
1879
|
+
yield this.localStorageSetItem(
|
|
1880
|
+
LOCAL_STORAGE_CURRENT_EXTERNAL_WALLET_ADDRESSES,
|
|
1881
|
+
JSON.stringify(currentExternalWalletAddresses)
|
|
1882
|
+
);
|
|
1883
|
+
});
|
|
1794
1884
|
}
|
|
1795
1885
|
/**
|
|
1796
1886
|
* Sets the login encryption key pair associated with the `ParaCore` instance.
|
|
1797
1887
|
* @param keyPair - Encryption key pair generated from loginEncryptionKey.
|
|
1798
1888
|
*/
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1889
|
+
setLoginEncryptionKeyPair(keyPair) {
|
|
1890
|
+
return __async(this, null, function* () {
|
|
1891
|
+
if (!keyPair) {
|
|
1892
|
+
keyPair = yield getAsymmetricKeyPair(this.ctx);
|
|
1893
|
+
}
|
|
1894
|
+
this.loginEncryptionKeyPair = keyPair;
|
|
1895
|
+
yield this.sessionStorageSetItem(SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR, JSON.stringify(keyPair));
|
|
1896
|
+
});
|
|
1805
1897
|
}
|
|
1806
|
-
|
|
1807
|
-
this
|
|
1808
|
-
|
|
1898
|
+
deleteLoginEncryptionKeyPair() {
|
|
1899
|
+
return __async(this, null, function* () {
|
|
1900
|
+
this.loginEncryptionKeyPair = void 0;
|
|
1901
|
+
yield this.sessionStorageRemoveItem(SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR);
|
|
1902
|
+
});
|
|
1809
1903
|
}
|
|
1810
1904
|
/**
|
|
1811
1905
|
* Gets the userId associated with the `ParaCore` instance.
|
|
@@ -1845,23 +1939,25 @@ var ParaCore = class _ParaCore {
|
|
|
1845
1939
|
getFarcasterUsername() {
|
|
1846
1940
|
return this.farcasterUsername;
|
|
1847
1941
|
}
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
this.
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1942
|
+
setCurrentWalletIds(_0) {
|
|
1943
|
+
return __async(this, arguments, function* (currentWalletIds, {
|
|
1944
|
+
needsWallet = false,
|
|
1945
|
+
sessionLookupId,
|
|
1946
|
+
newDeviceSessionLookupId
|
|
1947
|
+
} = {}) {
|
|
1948
|
+
this.currentWalletIds = currentWalletIds;
|
|
1949
|
+
yield this.localStorageSetItem(LOCAL_STORAGE_CURRENT_WALLET_IDS, JSON.stringify(this.currentWalletIds));
|
|
1950
|
+
if (sessionLookupId) {
|
|
1951
|
+
yield this.ctx.client.setCurrentWalletIds(
|
|
1952
|
+
this.getUserId(),
|
|
1953
|
+
this.currentWalletIds,
|
|
1954
|
+
needsWallet,
|
|
1955
|
+
sessionLookupId,
|
|
1956
|
+
newDeviceSessionLookupId
|
|
1957
|
+
);
|
|
1958
|
+
}
|
|
1959
|
+
dispatchEvent(ParaEvent.WALLETS_CHANGE_EVENT, null);
|
|
1960
|
+
});
|
|
1865
1961
|
}
|
|
1866
1962
|
/**
|
|
1867
1963
|
* Validates that a wallet ID is present on the instance, usable, and matches the desired filters.
|
|
@@ -1915,6 +2011,7 @@ var ParaCore = class _ParaCore {
|
|
|
1915
2011
|
return wallet;
|
|
1916
2012
|
}
|
|
1917
2013
|
findWallet(idOrAddress, overrideType, filter = {}) {
|
|
2014
|
+
var _b, _c;
|
|
1918
2015
|
if (!idOrAddress && Object.keys(this.externalWallets).length > 0) {
|
|
1919
2016
|
return Object.values(this.externalWallets)[0];
|
|
1920
2017
|
}
|
|
@@ -1924,18 +2021,18 @@ var ParaCore = class _ParaCore {
|
|
|
1924
2021
|
try {
|
|
1925
2022
|
const walletId = this.findWalletId(idOrAddress, filter);
|
|
1926
2023
|
if (walletId && !!this.wallets[walletId]) {
|
|
1927
|
-
const { signer: _signer,
|
|
1928
|
-
const type = overrideType
|
|
1929
|
-
return {
|
|
1930
|
-
...wallet,
|
|
2024
|
+
const _a = this.wallets[walletId], { signer: _signer } = _a, wallet = __objRest(_a, ["signer"]);
|
|
2025
|
+
const type = (_c = overrideType != null ? overrideType : (_b = this.currentWalletIdsArray.find(([id]) => id === walletId)) == null ? void 0 : _b[1]) != null ? _c : wallet.type;
|
|
2026
|
+
return __spreadProps(__spreadValues({}, wallet), {
|
|
1931
2027
|
type: import_user_management_client5.WalletType[type]
|
|
1932
|
-
};
|
|
2028
|
+
});
|
|
1933
2029
|
}
|
|
1934
2030
|
} catch (e) {
|
|
1935
2031
|
return void 0;
|
|
1936
2032
|
}
|
|
1937
2033
|
}
|
|
1938
2034
|
get availableWallets() {
|
|
2035
|
+
var _a;
|
|
1939
2036
|
return [
|
|
1940
2037
|
...this.currentWalletIdsArray.map(([address, type]) => [address, type, false]).map(([id, type]) => {
|
|
1941
2038
|
const wallet = this.findWallet(id, type);
|
|
@@ -1947,7 +2044,7 @@ var ParaCore = class _ParaCore {
|
|
|
1947
2044
|
name: wallet.name
|
|
1948
2045
|
};
|
|
1949
2046
|
}).filter((obj) => obj !== null),
|
|
1950
|
-
...Object.values(this.externalWallets
|
|
2047
|
+
...Object.values((_a = this.externalWallets) != null ? _a : {})
|
|
1951
2048
|
];
|
|
1952
2049
|
}
|
|
1953
2050
|
/**
|
|
@@ -1961,61 +2058,78 @@ var ParaCore = class _ParaCore {
|
|
|
1961
2058
|
assertIsValidWalletId(walletId, condition = {}) {
|
|
1962
2059
|
this.isWalletUsable(walletId, condition, true);
|
|
1963
2060
|
}
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
if (!this.#supportedWalletTypes) {
|
|
1975
|
-
await this.touchSession();
|
|
1976
|
-
}
|
|
1977
|
-
return this.supportedWalletTypes.filter(
|
|
1978
|
-
({ type: t, optional }) => !optional && Object.values(this.wallets).every((w) => !this.isWalletOwned(w) || !WalletSchemeTypeMap[w.scheme][t])
|
|
1979
|
-
).map(({ type }) => type);
|
|
2061
|
+
assertIsValidWalletType(type, walletTypes) {
|
|
2062
|
+
return __async(this, null, function* () {
|
|
2063
|
+
if (!__privateGet(this, _supportedWalletTypes)) {
|
|
2064
|
+
yield this.touchSession();
|
|
2065
|
+
}
|
|
2066
|
+
if (!type || !Object.values(import_user_management_client5.WalletType).includes(type) || !(walletTypes != null ? walletTypes : this.supportedWalletTypes.map(({ type: type2 }) => type2)).includes(type)) {
|
|
2067
|
+
throw new Error(`wallet type ${type} is not supported`);
|
|
2068
|
+
}
|
|
2069
|
+
return type;
|
|
2070
|
+
});
|
|
1980
2071
|
}
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
2072
|
+
getMissingTypes() {
|
|
2073
|
+
return __async(this, null, function* () {
|
|
2074
|
+
if (!__privateGet(this, _supportedWalletTypes)) {
|
|
2075
|
+
yield this.touchSession();
|
|
2076
|
+
}
|
|
2077
|
+
return this.supportedWalletTypes.filter(
|
|
2078
|
+
({ type: t, optional }) => !optional && Object.values(this.wallets).every((w) => !this.isWalletOwned(w) || !WalletSchemeTypeMap[w.scheme][t])
|
|
2079
|
+
).map(({ type }) => type);
|
|
2080
|
+
});
|
|
2081
|
+
}
|
|
2082
|
+
getTypesToCreate(types) {
|
|
2083
|
+
return __async(this, null, function* () {
|
|
2084
|
+
if (!__privateGet(this, _supportedWalletTypes)) {
|
|
2085
|
+
yield this.touchSession();
|
|
1991
2086
|
}
|
|
2087
|
+
return getSchemes(types != null ? types : yield this.getMissingTypes()).map((scheme) => {
|
|
2088
|
+
switch (scheme) {
|
|
2089
|
+
case import_user_management_client5.WalletScheme.ED25519:
|
|
2090
|
+
return import_user_management_client5.WalletType.SOLANA;
|
|
2091
|
+
default:
|
|
2092
|
+
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;
|
|
2093
|
+
}
|
|
2094
|
+
});
|
|
1992
2095
|
});
|
|
1993
2096
|
}
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
2097
|
+
getPartnerURL(partnerId) {
|
|
2098
|
+
return __async(this, null, function* () {
|
|
2099
|
+
const res = yield this.ctx.client.getPartner(partnerId);
|
|
2100
|
+
return res.data.partner.portalUrl;
|
|
2101
|
+
});
|
|
1997
2102
|
}
|
|
1998
2103
|
/**
|
|
1999
2104
|
* URL of the portal, which can be associated with a partner id
|
|
2000
2105
|
* @param partnerId: string - id of the partner to get the portal URL for
|
|
2001
2106
|
* @returns - portal URL
|
|
2002
2107
|
*/
|
|
2003
|
-
|
|
2004
|
-
return
|
|
2108
|
+
getPortalURL(partnerId) {
|
|
2109
|
+
return __async(this, null, function* () {
|
|
2110
|
+
return partnerId && (yield this.getPartnerURL(partnerId)) || getPortalBaseURL(this.ctx);
|
|
2111
|
+
});
|
|
2005
2112
|
}
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2113
|
+
getWebAuthURLForCreate(_a) {
|
|
2114
|
+
return __async(this, null, function* () {
|
|
2115
|
+
var _b = _a, {
|
|
2116
|
+
webAuthId
|
|
2117
|
+
} = _b, options = __objRest(_b, [
|
|
2118
|
+
"webAuthId"
|
|
2119
|
+
]);
|
|
2120
|
+
return this.constructPortalUrl("createAuth", __spreadProps(__spreadValues({}, options), { pathId: webAuthId }));
|
|
2121
|
+
});
|
|
2011
2122
|
}
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2123
|
+
getPasswordURLForCreate(_c) {
|
|
2124
|
+
return __async(this, null, function* () {
|
|
2125
|
+
var _d = _c, {
|
|
2126
|
+
passwordId
|
|
2127
|
+
} = _d, options = __objRest(_d, [
|
|
2128
|
+
"passwordId"
|
|
2129
|
+
]);
|
|
2130
|
+
return this.constructPortalUrl("createPassword", __spreadProps(__spreadValues({}, options), {
|
|
2131
|
+
pathId: passwordId
|
|
2132
|
+
}));
|
|
2019
2133
|
});
|
|
2020
2134
|
}
|
|
2021
2135
|
getShortUrl(compressedUrl) {
|
|
@@ -2024,35 +2138,42 @@ var ParaCore = class _ParaCore {
|
|
|
2024
2138
|
path: `/short/${compressedUrl}`
|
|
2025
2139
|
});
|
|
2026
2140
|
}
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2141
|
+
shortenLoginLink(link) {
|
|
2142
|
+
return __async(this, null, function* () {
|
|
2143
|
+
const url = yield upload(link, this.ctx.client);
|
|
2144
|
+
return this.getShortUrl(url);
|
|
2145
|
+
});
|
|
2030
2146
|
}
|
|
2031
2147
|
/**
|
|
2032
2148
|
* Generates a URL for registering a new WebAuth passkey.
|
|
2033
2149
|
* @param {GetWebAuthUrlForLoginParams} opts the options object
|
|
2034
2150
|
* @returns - the URL for creating a new passkey
|
|
2035
2151
|
*/
|
|
2036
|
-
|
|
2037
|
-
return this
|
|
2152
|
+
getWebAuthURLForLogin(opts) {
|
|
2153
|
+
return __async(this, null, function* () {
|
|
2154
|
+
return this.constructPortalUrl("loginAuth", opts);
|
|
2155
|
+
});
|
|
2038
2156
|
}
|
|
2039
2157
|
/**
|
|
2040
2158
|
* Generates a URL for registering a new user password.
|
|
2041
2159
|
* @param {GetWebAuthUrlForLoginParams} opts the options object
|
|
2042
2160
|
* @returns - the URL for creating a new password
|
|
2043
2161
|
*/
|
|
2044
|
-
|
|
2045
|
-
return this
|
|
2162
|
+
getPasswordURLForLogin(opts) {
|
|
2163
|
+
return __async(this, null, function* () {
|
|
2164
|
+
return this.constructPortalUrl("loginPassword", opts);
|
|
2165
|
+
});
|
|
2046
2166
|
}
|
|
2047
2167
|
/**
|
|
2048
2168
|
* Generates a URL for registering a new WebAuth passkey for a phone number.
|
|
2049
2169
|
* @param {Omit<GetWebAuthUrlForLoginParams, 'authType'>} opts the options object
|
|
2050
2170
|
* @returns - web auth url
|
|
2051
2171
|
*/
|
|
2052
|
-
|
|
2053
|
-
return this
|
|
2054
|
-
|
|
2055
|
-
|
|
2172
|
+
getWebAuthURLForLoginForPhone(opts) {
|
|
2173
|
+
return __async(this, null, function* () {
|
|
2174
|
+
return this.constructPortalUrl("loginAuth", __spreadValues({
|
|
2175
|
+
authType: "phone"
|
|
2176
|
+
}, opts));
|
|
2056
2177
|
});
|
|
2057
2178
|
}
|
|
2058
2179
|
/**
|
|
@@ -2060,57 +2181,59 @@ var ParaCore = class _ParaCore {
|
|
|
2060
2181
|
* @param {string } [walletId] id of the wallet to get the private key for. Will default to the first wallet if not provided.
|
|
2061
2182
|
* @returns - the private key string.
|
|
2062
2183
|
*/
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
this.
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2184
|
+
getPrivateKey(walletId) {
|
|
2185
|
+
return __async(this, null, function* () {
|
|
2186
|
+
const wallets = Object.values(this.wallets);
|
|
2187
|
+
const wallet = walletId ? this.wallets[walletId] : wallets == null ? void 0 : wallets[0];
|
|
2188
|
+
if (!wallet) {
|
|
2189
|
+
throw new Error("wallet not found");
|
|
2190
|
+
}
|
|
2191
|
+
if (wallet.scheme !== import_user_management_client5.WalletScheme.DKLS) {
|
|
2192
|
+
throw new Error("invalid wallet scheme");
|
|
2193
|
+
}
|
|
2194
|
+
return yield this.platformUtils.getPrivateKey(
|
|
2195
|
+
this.ctx,
|
|
2196
|
+
this.userId,
|
|
2197
|
+
wallet.id,
|
|
2198
|
+
wallet.signer,
|
|
2199
|
+
this.retrieveSessionCookie()
|
|
2200
|
+
);
|
|
2201
|
+
});
|
|
2079
2202
|
}
|
|
2080
2203
|
/**
|
|
2081
2204
|
* Fetches the wallets associated with the user.
|
|
2082
2205
|
* @returns {WalletEntity[]} wallets that were fetched.
|
|
2083
2206
|
*/
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2207
|
+
fetchWallets() {
|
|
2208
|
+
return __async(this, null, function* () {
|
|
2209
|
+
const res = yield this.isPortal() || this.isParaConnect() ? this.ctx.client.getAllWallets(this.userId) : this.ctx.client.getWallets(this.userId, true);
|
|
2210
|
+
return res.data.wallets.filter(
|
|
2211
|
+
(wallet) => !!wallet.address && (this.isParaConnect() || !this.isParaConnect() && this.isWalletSupported(entityToWallet(wallet)))
|
|
2212
|
+
);
|
|
2213
|
+
});
|
|
2089
2214
|
}
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
this.wallets[entity.id]
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2215
|
+
populateWalletAddresses() {
|
|
2216
|
+
return __async(this, null, function* () {
|
|
2217
|
+
const res = yield this.ctx.client.getWallets(this.userId, true);
|
|
2218
|
+
const wallets = res.data.wallets;
|
|
2219
|
+
wallets.forEach((entity) => {
|
|
2220
|
+
if (this.wallets[entity.id]) {
|
|
2221
|
+
this.wallets[entity.id] = __spreadValues(__spreadValues({}, entityToWallet(entity)), this.wallets[entity.id]);
|
|
2222
|
+
}
|
|
2223
|
+
});
|
|
2224
|
+
yield this.setWallets(this.wallets);
|
|
2100
2225
|
});
|
|
2101
|
-
await this.setWallets(this.wallets);
|
|
2102
2226
|
}
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
this.wallets[entity.id]
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2227
|
+
populatePregenWalletAddresses() {
|
|
2228
|
+
return __async(this, null, function* () {
|
|
2229
|
+
const res = yield this.getPregenWallets();
|
|
2230
|
+
res.forEach((entity) => {
|
|
2231
|
+
if (this.wallets[entity.id]) {
|
|
2232
|
+
this.wallets[entity.id] = __spreadValues(__spreadValues({}, entityToWallet(entity)), this.wallets[entity.id]);
|
|
2233
|
+
}
|
|
2234
|
+
});
|
|
2235
|
+
yield this.setWallets(this.wallets);
|
|
2112
2236
|
});
|
|
2113
|
-
await this.setWallets(this.wallets);
|
|
2114
2237
|
}
|
|
2115
2238
|
/**
|
|
2116
2239
|
* Checks if a user exists for an email address.
|
|
@@ -2118,9 +2241,11 @@ var ParaCore = class _ParaCore {
|
|
|
2118
2241
|
* @param {string} opts.email the email to check.
|
|
2119
2242
|
* @returns true if user exists, false otherwise.
|
|
2120
2243
|
*/
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2244
|
+
checkIfUserExists(_0) {
|
|
2245
|
+
return __async(this, arguments, function* ({ email }) {
|
|
2246
|
+
const res = yield this.ctx.client.checkUserExists({ email });
|
|
2247
|
+
return res.data.exists;
|
|
2248
|
+
});
|
|
2124
2249
|
}
|
|
2125
2250
|
/**
|
|
2126
2251
|
* Checks if a user exists for a phone number.
|
|
@@ -2129,23 +2254,26 @@ var ParaCore = class _ParaCore {
|
|
|
2129
2254
|
* @param {string} opts.countryCode - the country code.
|
|
2130
2255
|
* @returns true if user exists, false otherwise.
|
|
2131
2256
|
*/
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2257
|
+
checkIfUserExistsByPhone(_0) {
|
|
2258
|
+
return __async(this, arguments, function* ({ phone, countryCode }) {
|
|
2259
|
+
const res = yield this.ctx.client.checkUserExists({ phone, countryCode });
|
|
2260
|
+
return res.data.exists;
|
|
2261
|
+
});
|
|
2135
2262
|
}
|
|
2136
2263
|
/**
|
|
2137
2264
|
* Creates a new user.
|
|
2138
2265
|
* @param {Object} opts the options object
|
|
2139
2266
|
* @param {string} opts.email the email to use.
|
|
2140
2267
|
*/
|
|
2141
|
-
|
|
2142
|
-
this
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2268
|
+
createUser(_0) {
|
|
2269
|
+
return __async(this, arguments, function* ({ email }) {
|
|
2270
|
+
this.requireApiKey();
|
|
2271
|
+
yield this.setEmail(email);
|
|
2272
|
+
const { userId } = yield this.ctx.client.createUser(__spreadValues({
|
|
2273
|
+
email: this.email
|
|
2274
|
+
}, this.getVerificationEmailProps()));
|
|
2275
|
+
yield this.setUserId(userId);
|
|
2147
2276
|
});
|
|
2148
|
-
await this.setUserId(userId);
|
|
2149
2277
|
}
|
|
2150
2278
|
/**
|
|
2151
2279
|
* Creates a new user with a phone number.
|
|
@@ -2153,14 +2281,16 @@ var ParaCore = class _ParaCore {
|
|
|
2153
2281
|
* @param {string} opts.phone - the phone number to use for creating the user.
|
|
2154
2282
|
* @param {string} opts.countryCode - the country code to use for creating the user.
|
|
2155
2283
|
*/
|
|
2156
|
-
|
|
2157
|
-
this
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2284
|
+
createUserByPhone(_0) {
|
|
2285
|
+
return __async(this, arguments, function* ({ phone, countryCode }) {
|
|
2286
|
+
this.requireApiKey();
|
|
2287
|
+
yield this.setPhoneNumber(phone, countryCode);
|
|
2288
|
+
const { userId } = yield this.ctx.client.createUser({
|
|
2289
|
+
phone: this.phone,
|
|
2290
|
+
countryCode: this.countryCode
|
|
2291
|
+
});
|
|
2292
|
+
yield this.setUserId(userId);
|
|
2162
2293
|
});
|
|
2163
|
-
await this.setUserId(userId);
|
|
2164
2294
|
}
|
|
2165
2295
|
/**
|
|
2166
2296
|
* Logs in or creates a new user using an external wallet address.
|
|
@@ -2169,17 +2299,19 @@ var ParaCore = class _ParaCore {
|
|
|
2169
2299
|
* @param {WalletType} opts.type type of external wallet to use for identification.
|
|
2170
2300
|
* @param {string} opts.provider the name of the provider for the external wallet.
|
|
2171
2301
|
*/
|
|
2172
|
-
|
|
2173
|
-
this
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2302
|
+
externalWalletLogin(wallet) {
|
|
2303
|
+
return __async(this, null, function* () {
|
|
2304
|
+
this.requireApiKey();
|
|
2305
|
+
const res = yield this.ctx.client.externalWalletLogin({
|
|
2306
|
+
externalAddress: wallet.address,
|
|
2307
|
+
type: wallet.type,
|
|
2308
|
+
externalWalletProvider: wallet.provider,
|
|
2309
|
+
shouldTrackUser: wallet.shouldTrackUser
|
|
2310
|
+
});
|
|
2311
|
+
yield this.setExternalWallet(wallet);
|
|
2312
|
+
yield this.setUserId(res.userId);
|
|
2313
|
+
return res;
|
|
2314
|
+
});
|
|
2183
2315
|
}
|
|
2184
2316
|
/**
|
|
2185
2317
|
* Returns whether or not the user is connected with an external wallet.
|
|
@@ -2193,18 +2325,22 @@ var ParaCore = class _ParaCore {
|
|
|
2193
2325
|
* @param {string} verificationCode the six-digit code to check
|
|
2194
2326
|
* @returns {string} the web auth url for creating a new credential
|
|
2195
2327
|
*/
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2328
|
+
verifyEmail(_0) {
|
|
2329
|
+
return __async(this, arguments, function* ({ verificationCode }) {
|
|
2330
|
+
yield this.ctx.client.verifyEmail(this.userId, { verificationCode });
|
|
2331
|
+
return this.getSetUpBiometricsURL();
|
|
2332
|
+
});
|
|
2333
|
+
}
|
|
2334
|
+
verifyExternalWallet(_0) {
|
|
2335
|
+
return __async(this, arguments, function* ({
|
|
2336
|
+
address,
|
|
2337
|
+
signedMessage,
|
|
2338
|
+
cosmosPublicKeyHex,
|
|
2339
|
+
cosmosSigner
|
|
2340
|
+
}) {
|
|
2341
|
+
yield this.ctx.client.verifyExternalWallet(this.userId, { address, signedMessage, cosmosPublicKeyHex, cosmosSigner });
|
|
2342
|
+
return this.getSetUpBiometricsURL();
|
|
2343
|
+
});
|
|
2208
2344
|
}
|
|
2209
2345
|
/**
|
|
2210
2346
|
* Passes the phone code obtained from the user for verification.
|
|
@@ -2212,9 +2348,11 @@ var ParaCore = class _ParaCore {
|
|
|
2212
2348
|
* @param {string} verificationCode the six-digit code to check
|
|
2213
2349
|
* @returns {string} the web auth url for creating a new credential
|
|
2214
2350
|
*/
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2351
|
+
verifyPhone(_0) {
|
|
2352
|
+
return __async(this, arguments, function* ({ verificationCode }) {
|
|
2353
|
+
yield this.ctx.client.verifyPhone(this.userId, { verificationCode });
|
|
2354
|
+
return this.getSetUpBiometricsURLForPhone();
|
|
2355
|
+
});
|
|
2218
2356
|
}
|
|
2219
2357
|
/**
|
|
2220
2358
|
* Validates the response received from an attempted Telegram login for authenticity, then
|
|
@@ -2222,17 +2360,19 @@ var ParaCore = class _ParaCore {
|
|
|
2222
2360
|
* @param authResponse - the response JSON object received from the Telegram widget.
|
|
2223
2361
|
* @returns `{ isValid: boolean; telegramUserId?: string; userId?: string; isNewUser?: boolean; supportedAuthMethods?: AuthMethod[]; biometricHints?: BiometricLocationHint[] }`
|
|
2224
2362
|
*/
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2363
|
+
verifyTelegram(authObject) {
|
|
2364
|
+
return __async(this, null, function* () {
|
|
2365
|
+
const res = yield this.ctx.client.verifyTelegram(authObject);
|
|
2366
|
+
if (res.isValid) {
|
|
2367
|
+
yield this.setUserId(res.userId);
|
|
2368
|
+
yield this.setTelegramUserId(res.telegramUserId);
|
|
2369
|
+
yield this.touchSession(true);
|
|
2370
|
+
if (!this.loginEncryptionKeyPair) {
|
|
2371
|
+
yield this.setLoginEncryptionKeyPair();
|
|
2372
|
+
}
|
|
2233
2373
|
}
|
|
2234
|
-
|
|
2235
|
-
|
|
2374
|
+
return res;
|
|
2375
|
+
});
|
|
2236
2376
|
}
|
|
2237
2377
|
/**
|
|
2238
2378
|
* Performs 2FA verification.
|
|
@@ -2241,14 +2381,16 @@ var ParaCore = class _ParaCore {
|
|
|
2241
2381
|
* @param {string} opts.verificationCode the verification code to received via 2FA.
|
|
2242
2382
|
* @returns {Object} `{ address, initiatedAt, status, userId, walletId }`
|
|
2243
2383
|
*/
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2384
|
+
verify2FA(_0) {
|
|
2385
|
+
return __async(this, arguments, function* ({ email, verificationCode }) {
|
|
2386
|
+
const res = yield this.ctx.client.verify2FA(email, verificationCode);
|
|
2387
|
+
return {
|
|
2388
|
+
initiatedAt: res.data.initiatedAt,
|
|
2389
|
+
status: res.data.status,
|
|
2390
|
+
userId: res.data.userId,
|
|
2391
|
+
wallets: res.data.wallets
|
|
2392
|
+
};
|
|
2393
|
+
});
|
|
2252
2394
|
}
|
|
2253
2395
|
/**
|
|
2254
2396
|
* Performs 2FA verification.
|
|
@@ -2258,65 +2400,76 @@ var ParaCore = class _ParaCore {
|
|
|
2258
2400
|
* @param {string} opts.verificationCode - verification code to received via 2FA.
|
|
2259
2401
|
* @returns {Object} `{ address, initiatedAt, status, userId, walletId }`
|
|
2260
2402
|
*/
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2403
|
+
verify2FAForPhone(_0) {
|
|
2404
|
+
return __async(this, arguments, function* ({
|
|
2405
|
+
phone,
|
|
2406
|
+
countryCode,
|
|
2407
|
+
verificationCode
|
|
2408
|
+
}) {
|
|
2409
|
+
const res = yield this.ctx.client.verify2FAForPhone(phone, countryCode, verificationCode);
|
|
2410
|
+
return {
|
|
2411
|
+
initiatedAt: res.data.initiatedAt,
|
|
2412
|
+
status: res.data.status,
|
|
2413
|
+
userId: res.data.userId,
|
|
2414
|
+
wallets: res.data.wallets
|
|
2415
|
+
};
|
|
2416
|
+
});
|
|
2273
2417
|
}
|
|
2274
2418
|
/**
|
|
2275
2419
|
* Sets up two-factor authentication for the current user.
|
|
2276
2420
|
* @returns {string} uri - uri to use for setting up 2FA
|
|
2277
2421
|
* */
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2422
|
+
setup2FA() {
|
|
2423
|
+
return __async(this, null, function* () {
|
|
2424
|
+
const res = yield this.ctx.client.setup2FA(this.userId);
|
|
2425
|
+
return {
|
|
2426
|
+
uri: res.data.uri
|
|
2427
|
+
};
|
|
2428
|
+
});
|
|
2283
2429
|
}
|
|
2284
2430
|
/**
|
|
2285
2431
|
* Enables 2FA.
|
|
2286
2432
|
* @param {Object} opts the options object
|
|
2287
2433
|
* @param {string} opts.verificationCode - the verification code received via 2FA.
|
|
2288
2434
|
*/
|
|
2289
|
-
|
|
2290
|
-
|
|
2435
|
+
enable2FA(_0) {
|
|
2436
|
+
return __async(this, arguments, function* ({ verificationCode }) {
|
|
2437
|
+
yield this.ctx.client.enable2FA(this.userId, verificationCode);
|
|
2438
|
+
});
|
|
2291
2439
|
}
|
|
2292
2440
|
/**
|
|
2293
2441
|
* Determines if 2FA has been set up.
|
|
2294
2442
|
* @returns {Object} `{ isSetup: boolean }` - true if 2FA is setup, false otherwise
|
|
2295
2443
|
*/
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2444
|
+
check2FAStatus() {
|
|
2445
|
+
return __async(this, null, function* () {
|
|
2446
|
+
if (!this.userId) {
|
|
2447
|
+
return { isSetup: false };
|
|
2448
|
+
}
|
|
2449
|
+
const res = yield this.ctx.client.check2FAStatus(this.userId);
|
|
2450
|
+
return {
|
|
2451
|
+
isSetup: res.data.isSetup
|
|
2452
|
+
};
|
|
2453
|
+
});
|
|
2304
2454
|
}
|
|
2305
2455
|
/**
|
|
2306
2456
|
* Resend a verification email for the current user.
|
|
2307
2457
|
*/
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2458
|
+
resendVerificationCode() {
|
|
2459
|
+
return __async(this, null, function* () {
|
|
2460
|
+
yield this.ctx.client.resendVerificationCode(__spreadValues({
|
|
2461
|
+
userId: this.userId
|
|
2462
|
+
}, this.getVerificationEmailProps()));
|
|
2312
2463
|
});
|
|
2313
2464
|
}
|
|
2314
2465
|
/**
|
|
2315
2466
|
* Resend a verification SMS for the current user.
|
|
2316
2467
|
*/
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2468
|
+
resendVerificationCodeByPhone() {
|
|
2469
|
+
return __async(this, null, function* () {
|
|
2470
|
+
yield this.ctx.client.resendVerificationCodeByPhone({
|
|
2471
|
+
userId: this.userId
|
|
2472
|
+
});
|
|
2320
2473
|
});
|
|
2321
2474
|
}
|
|
2322
2475
|
/**
|
|
@@ -2326,19 +2479,21 @@ var ParaCore = class _ParaCore {
|
|
|
2326
2479
|
* @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
|
|
2327
2480
|
* @returns {string} the URL
|
|
2328
2481
|
*/
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2482
|
+
getSetUpBiometricsURL() {
|
|
2483
|
+
return __async(this, arguments, function* ({
|
|
2484
|
+
authType = "email",
|
|
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,
|
|
2493
|
+
isForNewDevice,
|
|
2494
|
+
webAuthId: res.data.id,
|
|
2495
|
+
partnerId: res.data.partnerId
|
|
2496
|
+
});
|
|
2342
2497
|
});
|
|
2343
2498
|
}
|
|
2344
2499
|
/**
|
|
@@ -2347,18 +2502,20 @@ var ParaCore = class _ParaCore {
|
|
|
2347
2502
|
* @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
|
|
2348
2503
|
* @returns {string} the URL
|
|
2349
2504
|
*/
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2505
|
+
getSetUpBiometricsURLForPhone() {
|
|
2506
|
+
return __async(this, arguments, function* ({
|
|
2507
|
+
isForNewDevice = false
|
|
2508
|
+
} = {}) {
|
|
2509
|
+
const res = yield this.ctx.client.addSessionPublicKey(this.userId, {
|
|
2510
|
+
status: import_user_management_client5.PublicKeyStatus.PENDING,
|
|
2511
|
+
type: import_user_management_client5.PublicKeyType.WEB
|
|
2512
|
+
});
|
|
2513
|
+
return this.getWebAuthURLForCreate({
|
|
2514
|
+
authType: "phone",
|
|
2515
|
+
isForNewDevice,
|
|
2516
|
+
webAuthId: res.data.id,
|
|
2517
|
+
partnerId: res.data.partnerId
|
|
2518
|
+
});
|
|
2362
2519
|
});
|
|
2363
2520
|
}
|
|
2364
2521
|
/**
|
|
@@ -2369,95 +2526,107 @@ var ParaCore = class _ParaCore {
|
|
|
2369
2526
|
* @param {Theme} [opts.theme] the portal theme to use in place of the partner's default
|
|
2370
2527
|
* @returns {string} the URL
|
|
2371
2528
|
*/
|
|
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,
|
|
2529
|
+
getSetupPasswordURL() {
|
|
2530
|
+
return __async(this, arguments, function* ({
|
|
2531
|
+
authType = "email",
|
|
2532
|
+
isForNewDevice = false,
|
|
2385
2533
|
theme
|
|
2534
|
+
} = {}) {
|
|
2535
|
+
const res = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
|
|
2536
|
+
status: import_user_management_client5.PasswordStatus.PENDING
|
|
2537
|
+
});
|
|
2538
|
+
return this.getPasswordURLForCreate({
|
|
2539
|
+
authType,
|
|
2540
|
+
isForNewDevice,
|
|
2541
|
+
passwordId: res.data.id,
|
|
2542
|
+
partnerId: res.data.partnerId,
|
|
2543
|
+
theme
|
|
2544
|
+
});
|
|
2386
2545
|
});
|
|
2387
2546
|
}
|
|
2388
2547
|
/**
|
|
2389
2548
|
* Checks if the current session is active.
|
|
2390
2549
|
* @returns `true` if active, `false` otherwise
|
|
2391
2550
|
*/
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2551
|
+
isSessionActive() {
|
|
2552
|
+
return __async(this, null, function* () {
|
|
2553
|
+
if (this.isUsingExternalWallet()) {
|
|
2554
|
+
return true;
|
|
2555
|
+
}
|
|
2556
|
+
const res = yield this.touchSession();
|
|
2557
|
+
return !!res.data.isAuthenticated;
|
|
2558
|
+
});
|
|
2398
2559
|
}
|
|
2399
2560
|
/**
|
|
2400
2561
|
* Checks if a session is active and a wallet exists.
|
|
2401
2562
|
* @returns `true` if active, `false` otherwise
|
|
2402
2563
|
**/
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2564
|
+
isFullyLoggedIn() {
|
|
2565
|
+
return __async(this, null, function* () {
|
|
2566
|
+
if (this.isUsingExternalWallet()) {
|
|
2567
|
+
return true;
|
|
2568
|
+
}
|
|
2569
|
+
const isSessionActive = yield this.isSessionActive();
|
|
2570
|
+
return isSessionActive && this.currentWalletIdsArray.length > 0 && this.currentWalletIdsArray.reduce((acc, [id]) => acc && !!this.wallets[id], true);
|
|
2571
|
+
});
|
|
2409
2572
|
}
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2573
|
+
supportedAuthMethods(auth) {
|
|
2574
|
+
return __async(this, null, function* () {
|
|
2575
|
+
const { supportedAuthMethods } = yield this.ctx.client.getSupportedAuthMethods(auth);
|
|
2576
|
+
const authMethods = /* @__PURE__ */ new Set();
|
|
2577
|
+
for (const type of supportedAuthMethods) {
|
|
2578
|
+
switch (type) {
|
|
2579
|
+
case "PASSWORD":
|
|
2580
|
+
authMethods.add(import_user_management_client5.AuthMethod.PASSWORD);
|
|
2581
|
+
break;
|
|
2582
|
+
case "BIOMETRIC":
|
|
2583
|
+
authMethods.add(import_user_management_client5.AuthMethod.PASSKEY);
|
|
2584
|
+
break;
|
|
2585
|
+
}
|
|
2421
2586
|
}
|
|
2422
|
-
|
|
2423
|
-
|
|
2587
|
+
return authMethods;
|
|
2588
|
+
});
|
|
2424
2589
|
}
|
|
2425
2590
|
/**
|
|
2426
2591
|
* Get hints associated with the users stored biometrics.
|
|
2427
2592
|
* @returns Array containing useragents and AAGuids for stored biometrics
|
|
2428
2593
|
*/
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2594
|
+
getUserBiometricLocationHints() {
|
|
2595
|
+
return __async(this, null, function* () {
|
|
2596
|
+
if (!this.email && !this.phone && !this.farcasterUsername && !this.telegramUserId) {
|
|
2597
|
+
throw new Error("one of email, phone or farcaster username are required to get biometric location hints");
|
|
2598
|
+
}
|
|
2599
|
+
return yield this.ctx.client.getBiometricLocationHints({
|
|
2600
|
+
email: this.email,
|
|
2601
|
+
phone: this.phone,
|
|
2602
|
+
countryCode: this.countryCode,
|
|
2603
|
+
farcasterUsername: this.farcasterUsername,
|
|
2604
|
+
telegramUserId: this.telegramUserId
|
|
2605
|
+
});
|
|
2439
2606
|
});
|
|
2440
2607
|
}
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2608
|
+
setAuth(auth) {
|
|
2609
|
+
return __async(this, null, function* () {
|
|
2610
|
+
const authInfo = (0, import_user_management_client5.extractAuthInfo)(auth);
|
|
2611
|
+
if (!authInfo) {
|
|
2612
|
+
return void 0;
|
|
2613
|
+
}
|
|
2614
|
+
switch (authInfo.authType) {
|
|
2615
|
+
case "email":
|
|
2616
|
+
yield this.setEmail(authInfo.identifier);
|
|
2617
|
+
break;
|
|
2618
|
+
case "phone":
|
|
2619
|
+
yield this.setPhoneNumber(authInfo.auth.phone, authInfo.auth.countryCode);
|
|
2620
|
+
break;
|
|
2621
|
+
case "farcaster":
|
|
2622
|
+
yield this.setFarcasterUsername(authInfo.identifier);
|
|
2623
|
+
break;
|
|
2624
|
+
case "telegram":
|
|
2625
|
+
yield this.setTelegramUserId(authInfo.identifier);
|
|
2626
|
+
break;
|
|
2627
|
+
}
|
|
2628
|
+
return authInfo;
|
|
2629
|
+
});
|
|
2461
2630
|
}
|
|
2462
2631
|
/**
|
|
2463
2632
|
* Initiates a login.
|
|
@@ -2466,41 +2635,46 @@ var ParaCore = class _ParaCore {
|
|
|
2466
2635
|
* @param {boolean} opts.useShortURL - whether to shorten the link
|
|
2467
2636
|
* @returns - the WebAuth URL for logging in
|
|
2468
2637
|
**/
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2638
|
+
initiateUserLogin(_e) {
|
|
2639
|
+
return __async(this, null, function* () {
|
|
2640
|
+
var _f = _e, { useShortUrl = false } = _f, auth = __objRest(_f, ["useShortUrl"]);
|
|
2641
|
+
const authInfo = yield this.setAuth(auth);
|
|
2642
|
+
if (!authInfo) {
|
|
2643
|
+
return;
|
|
2644
|
+
}
|
|
2645
|
+
const res = yield this.touchSession(true);
|
|
2646
|
+
if (!this.loginEncryptionKeyPair) {
|
|
2647
|
+
yield this.setLoginEncryptionKeyPair();
|
|
2648
|
+
}
|
|
2649
|
+
const webAuthLoginURL = yield this.getWebAuthURLForLogin({
|
|
2650
|
+
authType: authInfo.authType,
|
|
2651
|
+
sessionId: res.data.sessionId,
|
|
2652
|
+
partnerId: res.data.partnerId,
|
|
2653
|
+
loginEncryptionPublicKey: getPublicKeyHex(this.loginEncryptionKeyPair)
|
|
2654
|
+
});
|
|
2655
|
+
if (!useShortUrl) {
|
|
2656
|
+
return webAuthLoginURL;
|
|
2657
|
+
}
|
|
2658
|
+
return this.shortenLoginLink(webAuthLoginURL);
|
|
2659
|
+
});
|
|
2488
2660
|
}
|
|
2489
2661
|
/**
|
|
2490
2662
|
* Initiates a login.
|
|
2491
2663
|
* @param email - the email to login with
|
|
2492
2664
|
* @returns - a set of supported auth methods for the user
|
|
2493
2665
|
**/
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2666
|
+
initiateUserLoginV2(auth) {
|
|
2667
|
+
return __async(this, null, function* () {
|
|
2668
|
+
const authInfo = yield this.setAuth(auth);
|
|
2669
|
+
if (!authInfo) {
|
|
2670
|
+
return;
|
|
2671
|
+
}
|
|
2672
|
+
yield this.touchSession(true);
|
|
2673
|
+
if (!this.loginEncryptionKeyPair) {
|
|
2674
|
+
yield this.setLoginEncryptionKeyPair();
|
|
2675
|
+
}
|
|
2676
|
+
return yield this.supportedAuthMethods(authInfo.auth);
|
|
2677
|
+
});
|
|
2504
2678
|
}
|
|
2505
2679
|
/**
|
|
2506
2680
|
* Initiates a login.
|
|
@@ -2510,113 +2684,125 @@ var ParaCore = class _ParaCore {
|
|
|
2510
2684
|
* @param opts.useShortURL - whether to shorten the link
|
|
2511
2685
|
* @returns - the WebAuth URL for logging in
|
|
2512
2686
|
**/
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2687
|
+
initiateUserLoginForPhone(_g) {
|
|
2688
|
+
return __async(this, null, function* () {
|
|
2689
|
+
var _h = _g, {
|
|
2690
|
+
useShortUrl = false
|
|
2691
|
+
} = _h, auth = __objRest(_h, [
|
|
2692
|
+
"useShortUrl"
|
|
2693
|
+
]);
|
|
2694
|
+
yield this.setAuth(auth);
|
|
2695
|
+
const res = yield this.touchSession(true);
|
|
2696
|
+
if (!this.loginEncryptionKeyPair) {
|
|
2697
|
+
yield this.setLoginEncryptionKeyPair();
|
|
2698
|
+
}
|
|
2699
|
+
const webAuthLoginURL = yield this.getWebAuthURLForLoginForPhone({
|
|
2700
|
+
sessionId: res.data.sessionId,
|
|
2701
|
+
loginEncryptionPublicKey: getPublicKeyHex(this.loginEncryptionKeyPair),
|
|
2702
|
+
partnerId: res.data.partnerId
|
|
2703
|
+
});
|
|
2704
|
+
if (!useShortUrl) {
|
|
2705
|
+
return webAuthLoginURL;
|
|
2706
|
+
}
|
|
2707
|
+
return this.shortenLoginLink(webAuthLoginURL);
|
|
2526
2708
|
});
|
|
2527
|
-
if (!useShortUrl) {
|
|
2528
|
-
return webAuthLoginURL;
|
|
2529
|
-
}
|
|
2530
|
-
return this.shortenLoginLink(webAuthLoginURL);
|
|
2531
2709
|
}
|
|
2532
2710
|
/**
|
|
2533
2711
|
* Waits for the session to be active.
|
|
2534
2712
|
**/
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
this.
|
|
2545
|
-
dispatchEvent(ParaEvent.ACCOUNT_CREATION_EVENT, true);
|
|
2546
|
-
return true;
|
|
2547
|
-
} else {
|
|
2548
|
-
if (popupWindow?.closed) {
|
|
2713
|
+
waitForAccountCreation() {
|
|
2714
|
+
return __async(this, arguments, function* ({ popupWindow } = {}) {
|
|
2715
|
+
yield this.touchSession();
|
|
2716
|
+
this.currentExternalWalletAddresses = void 0;
|
|
2717
|
+
this.externalWallets = {};
|
|
2718
|
+
this.isAwaitingAccountCreation = true;
|
|
2719
|
+
while (this.isAwaitingAccountCreation) {
|
|
2720
|
+
try {
|
|
2721
|
+
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
2722
|
+
if (yield this.isSessionActive()) {
|
|
2549
2723
|
this.isAwaitingAccountCreation = false;
|
|
2550
|
-
|
|
2724
|
+
dispatchEvent(ParaEvent.ACCOUNT_CREATION_EVENT, true);
|
|
2725
|
+
return true;
|
|
2726
|
+
} else {
|
|
2727
|
+
if (popupWindow == null ? void 0 : popupWindow.closed) {
|
|
2728
|
+
this.isAwaitingAccountCreation = false;
|
|
2729
|
+
return false;
|
|
2730
|
+
}
|
|
2551
2731
|
}
|
|
2732
|
+
} catch (err) {
|
|
2733
|
+
console.error(err);
|
|
2552
2734
|
}
|
|
2553
|
-
} catch (err) {
|
|
2554
|
-
console.error(err);
|
|
2555
2735
|
}
|
|
2556
|
-
|
|
2557
|
-
|
|
2736
|
+
return false;
|
|
2737
|
+
});
|
|
2558
2738
|
}
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2739
|
+
waitForPasskeyAndCreateWallet() {
|
|
2740
|
+
return __async(this, arguments, function* ({
|
|
2741
|
+
popupWindow
|
|
2742
|
+
} = {}) {
|
|
2743
|
+
yield this.waitForAccountCreation({ popupWindow });
|
|
2744
|
+
const pregenWallets = yield this.getPregenWallets();
|
|
2745
|
+
let recoverySecret, walletIds = {};
|
|
2746
|
+
if (pregenWallets.length > 0) {
|
|
2747
|
+
recoverySecret = yield this.claimPregenWallets();
|
|
2748
|
+
walletIds = this.supportedWalletTypes.reduce((acc, { type }) => {
|
|
2749
|
+
var _a;
|
|
2750
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
2751
|
+
[type]: [(_a = pregenWallets.find((w) => !!WalletSchemeTypeMap[w.scheme][type])) == null ? void 0 : _a.id]
|
|
2752
|
+
});
|
|
2753
|
+
}, {});
|
|
2754
|
+
}
|
|
2755
|
+
const created = yield this.createWalletPerType();
|
|
2756
|
+
recoverySecret = recoverySecret != null ? recoverySecret : created.recoverySecret;
|
|
2757
|
+
walletIds = __spreadValues(__spreadValues({}, walletIds), created.walletIds);
|
|
2758
|
+
const resp = { walletIds, recoverySecret };
|
|
2759
|
+
dispatchEvent(ParaEvent.ACCOUNT_SETUP_EVENT, resp);
|
|
2760
|
+
return resp;
|
|
2761
|
+
});
|
|
2580
2762
|
}
|
|
2581
2763
|
/**
|
|
2582
2764
|
* Initiates a Farcaster login attempt and return the URI for the user to connect.
|
|
2583
2765
|
* You can create a QR code with this URI that works with Farcaster's mobile app.
|
|
2584
2766
|
* @return {string} the Farcaster connect URI
|
|
2585
2767
|
*/
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2768
|
+
getFarcasterConnectURL() {
|
|
2769
|
+
return __async(this, null, function* () {
|
|
2770
|
+
yield this.logout();
|
|
2771
|
+
yield this.touchSession(true);
|
|
2772
|
+
const {
|
|
2773
|
+
data: { connect_uri }
|
|
2774
|
+
} = yield this.ctx.client.initializeFarcasterLogin();
|
|
2775
|
+
return connect_uri;
|
|
2776
|
+
});
|
|
2593
2777
|
}
|
|
2594
2778
|
/**
|
|
2595
2779
|
* Awaits the response from a user's attempt to log in with Farcaster.
|
|
2596
2780
|
* If successful, this returns the user's Farcaster username and profile picture and indicates whether the user already exists.
|
|
2597
2781
|
* @return {Object} `{userExists: boolean; username: string; pfpUrl?: string | null }` - the user's information and whether the user already exists.
|
|
2598
2782
|
*/
|
|
2599
|
-
|
|
2600
|
-
this
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2783
|
+
waitForFarcasterStatus() {
|
|
2784
|
+
return __async(this, null, function* () {
|
|
2785
|
+
this.isAwaitingFarcaster = true;
|
|
2786
|
+
while (this.isAwaitingFarcaster) {
|
|
2787
|
+
try {
|
|
2788
|
+
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
2789
|
+
const res = yield this.ctx.client.getFarcasterAuthStatus();
|
|
2790
|
+
if (res.data.state === "completed") {
|
|
2791
|
+
const { userId, userExists, username, pfpUrl } = res.data;
|
|
2792
|
+
yield this.setUserId(userId);
|
|
2793
|
+
yield this.setFarcasterUsername(username);
|
|
2794
|
+
return {
|
|
2795
|
+
userExists,
|
|
2796
|
+
username,
|
|
2797
|
+
pfpUrl
|
|
2798
|
+
};
|
|
2799
|
+
}
|
|
2800
|
+
} catch (err) {
|
|
2801
|
+
console.error(err);
|
|
2802
|
+
this.isAwaitingFarcaster = false;
|
|
2614
2803
|
}
|
|
2615
|
-
} catch (err) {
|
|
2616
|
-
console.error(err);
|
|
2617
|
-
this.isAwaitingFarcaster = false;
|
|
2618
2804
|
}
|
|
2619
|
-
}
|
|
2805
|
+
});
|
|
2620
2806
|
}
|
|
2621
2807
|
/**
|
|
2622
2808
|
* Generates a URL for the user to log in with OAuth using a desire method.
|
|
@@ -2626,17 +2812,19 @@ var ParaCore = class _ParaCore {
|
|
|
2626
2812
|
* @param {string} [opts.deeplinkUrl] the deeplink to redirect to after the OAuth flow. This is for mobile only.
|
|
2627
2813
|
* @returns {string} the URL for the user to log in with OAuth.
|
|
2628
2814
|
*/
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2815
|
+
getOAuthURL(_0) {
|
|
2816
|
+
return __async(this, arguments, function* ({ method, deeplinkUrl }) {
|
|
2817
|
+
yield this.logout();
|
|
2818
|
+
const res = yield this.touchSession(true);
|
|
2819
|
+
return constructUrl({
|
|
2820
|
+
base: method === import_user_management_client5.OAuthMethod.TELEGRAM ? getPortalBaseURL(this.ctx, true) : getBaseOAuthUrl(this.ctx.env),
|
|
2821
|
+
path: `/auth/${method.toLowerCase()}`,
|
|
2822
|
+
params: {
|
|
2823
|
+
apiKey: this.ctx.apiKey,
|
|
2824
|
+
sessionLookupId: res.data.sessionLookupId,
|
|
2825
|
+
deeplinkUrl
|
|
2826
|
+
}
|
|
2827
|
+
});
|
|
2640
2828
|
});
|
|
2641
2829
|
}
|
|
2642
2830
|
/**
|
|
@@ -2647,36 +2835,38 @@ var ParaCore = class _ParaCore {
|
|
|
2647
2835
|
* @param {Window} [opts.popupWindow] the popup window being used for login.
|
|
2648
2836
|
* @return {Object} `{ email?: string; isError?: boolean; userExists: boolean; }` the result data
|
|
2649
2837
|
*/
|
|
2650
|
-
|
|
2651
|
-
this
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2838
|
+
waitForOAuth() {
|
|
2839
|
+
return __async(this, arguments, function* ({ popupWindow } = {}) {
|
|
2840
|
+
this.isAwaitingOAuth = true;
|
|
2841
|
+
while (this.isAwaitingOAuth) {
|
|
2842
|
+
try {
|
|
2843
|
+
if (popupWindow == null ? void 0 : popupWindow.closed) {
|
|
2844
|
+
return { isError: true, userExists: false };
|
|
2845
|
+
}
|
|
2846
|
+
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
2847
|
+
if (this.isAwaitingOAuth) {
|
|
2848
|
+
const res = yield this.touchSession();
|
|
2849
|
+
if (res.data.userId) {
|
|
2850
|
+
const { userId, email } = res.data;
|
|
2851
|
+
if (!this.loginEncryptionKeyPair) {
|
|
2852
|
+
yield this.setLoginEncryptionKeyPair();
|
|
2853
|
+
}
|
|
2854
|
+
yield this.setUserId(userId);
|
|
2855
|
+
yield this.setEmail(email);
|
|
2856
|
+
const userExists = yield this.checkIfUserExists({ email });
|
|
2857
|
+
this.isAwaitingOAuth = false;
|
|
2858
|
+
return {
|
|
2859
|
+
userExists,
|
|
2860
|
+
email
|
|
2861
|
+
};
|
|
2664
2862
|
}
|
|
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
2863
|
}
|
|
2864
|
+
} catch (err) {
|
|
2865
|
+
console.error(err);
|
|
2674
2866
|
}
|
|
2675
|
-
} catch (err) {
|
|
2676
|
-
console.error(err);
|
|
2677
2867
|
}
|
|
2678
|
-
|
|
2679
|
-
|
|
2868
|
+
return { userExists: false };
|
|
2869
|
+
});
|
|
2680
2870
|
}
|
|
2681
2871
|
/**
|
|
2682
2872
|
* Waits for the session to be active and sets up the user.
|
|
@@ -2686,57 +2876,60 @@ var ParaCore = class _ParaCore {
|
|
|
2686
2876
|
* @param {boolean} [opts.skipSessionRefresh] whether to skip refreshing the session.
|
|
2687
2877
|
* @returns {Object} `{ isComplete: boolean; isError: boolean; needsWallet: boolean; partnerId: string; }` the result data
|
|
2688
2878
|
**/
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
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) {
|
|
2879
|
+
waitForLoginAndSetup() {
|
|
2880
|
+
return __async(this, arguments, function* ({
|
|
2881
|
+
popupWindow,
|
|
2882
|
+
skipSessionRefresh = false
|
|
2883
|
+
} = {}) {
|
|
2884
|
+
var _a;
|
|
2885
|
+
this.currentExternalWalletAddresses = void 0;
|
|
2886
|
+
this.externalWallets = {};
|
|
2887
|
+
this.isAwaitingLogin = true;
|
|
2888
|
+
while (this.isAwaitingLogin) {
|
|
2889
|
+
try {
|
|
2890
|
+
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
2891
|
+
if (!(yield this.isSessionActive())) {
|
|
2892
|
+
if (popupWindow == null ? void 0 : popupWindow.closed) {
|
|
2712
2893
|
const resp2 = { isComplete: false, isError: true };
|
|
2713
2894
|
dispatchEvent(ParaEvent.LOGIN_EVENT, resp2, "failed to setup user");
|
|
2714
2895
|
return resp2;
|
|
2715
|
-
} else {
|
|
2716
|
-
continue;
|
|
2717
2896
|
}
|
|
2897
|
+
continue;
|
|
2718
2898
|
}
|
|
2899
|
+
const postLoginData = yield this.userSetupAfterLogin();
|
|
2900
|
+
const needsWallet = (_a = postLoginData.data.needsWallet) != null ? _a : false;
|
|
2901
|
+
if (!needsWallet) {
|
|
2902
|
+
if (this.currentWalletIdsArray.length === 0) {
|
|
2903
|
+
if (popupWindow == null ? void 0 : popupWindow.closed) {
|
|
2904
|
+
const resp2 = { isComplete: false, isError: true };
|
|
2905
|
+
dispatchEvent(ParaEvent.LOGIN_EVENT, resp2, "failed to setup user");
|
|
2906
|
+
return resp2;
|
|
2907
|
+
} else {
|
|
2908
|
+
continue;
|
|
2909
|
+
}
|
|
2910
|
+
}
|
|
2911
|
+
}
|
|
2912
|
+
const fetchedWallets = yield this.fetchWallets();
|
|
2913
|
+
const tempSharesRes = yield this.getTransmissionKeyShares();
|
|
2914
|
+
if (tempSharesRes.data.temporaryShares.length === fetchedWallets.length) {
|
|
2915
|
+
yield this.setupAfterLogin({ temporaryShares: tempSharesRes.data.temporaryShares, skipSessionRefresh });
|
|
2916
|
+
yield this.claimPregenWallets();
|
|
2917
|
+
const resp2 = {
|
|
2918
|
+
isComplete: true,
|
|
2919
|
+
needsWallet: needsWallet || Object.values(this.wallets).length === 0,
|
|
2920
|
+
partnerId: postLoginData.data.partnerId
|
|
2921
|
+
};
|
|
2922
|
+
dispatchEvent(ParaEvent.LOGIN_EVENT, resp2);
|
|
2923
|
+
return resp2;
|
|
2924
|
+
}
|
|
2925
|
+
} catch (err) {
|
|
2926
|
+
console.error(err);
|
|
2719
2927
|
}
|
|
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
2928
|
}
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2929
|
+
const resp = { isComplete: false };
|
|
2930
|
+
dispatchEvent(ParaEvent.LOGIN_EVENT, resp, "exitted login without setting up user");
|
|
2931
|
+
return resp;
|
|
2932
|
+
});
|
|
2740
2933
|
}
|
|
2741
2934
|
/**
|
|
2742
2935
|
* Updates the session with the user management server, possibly
|
|
@@ -2746,32 +2939,36 @@ var ParaCore = class _ParaCore {
|
|
|
2746
2939
|
* @param {boolean} [shouldOpenPopup] - if `true`, the running device will open a popup to reauthenticate the user.
|
|
2747
2940
|
* @returns a URL for the user to reauthenticate.
|
|
2748
2941
|
**/
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2942
|
+
refreshSession() {
|
|
2943
|
+
return __async(this, arguments, function* ({ shouldOpenPopup = false } = {}) {
|
|
2944
|
+
const res = yield this.touchSession(true);
|
|
2945
|
+
if (!this.loginEncryptionKeyPair) {
|
|
2946
|
+
yield this.setLoginEncryptionKeyPair();
|
|
2947
|
+
}
|
|
2948
|
+
const link = yield this.getWebAuthURLForLogin({
|
|
2949
|
+
sessionId: res.data.sessionId,
|
|
2950
|
+
loginEncryptionPublicKey: getPublicKeyHex(this.loginEncryptionKeyPair)
|
|
2951
|
+
});
|
|
2952
|
+
if (shouldOpenPopup) {
|
|
2953
|
+
this.platformUtils.openPopup(link);
|
|
2954
|
+
}
|
|
2955
|
+
return link;
|
|
2757
2956
|
});
|
|
2758
|
-
if (shouldOpenPopup) {
|
|
2759
|
-
this.platformUtils.openPopup(link);
|
|
2760
|
-
}
|
|
2761
|
-
return link;
|
|
2762
2957
|
}
|
|
2763
2958
|
/**
|
|
2764
2959
|
* Call this method after login to ensure that the user ID is set
|
|
2765
2960
|
* internally.
|
|
2766
2961
|
**/
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2962
|
+
userSetupAfterLogin() {
|
|
2963
|
+
return __async(this, null, function* () {
|
|
2964
|
+
const res = yield this.touchSession();
|
|
2965
|
+
yield this.setUserId(res.data.userId);
|
|
2966
|
+
if (res.data.currentWalletIds && res.data.currentWalletIds !== this.currentWalletIds)
|
|
2967
|
+
yield this.setCurrentWalletIds(res.data.currentWalletIds, {
|
|
2968
|
+
sessionLookupId: this.isPortal() ? res.data.sessionLookupId : void 0
|
|
2969
|
+
});
|
|
2970
|
+
return res;
|
|
2971
|
+
});
|
|
2775
2972
|
}
|
|
2776
2973
|
/**
|
|
2777
2974
|
* Get transmission shares associated with session.
|
|
@@ -2779,10 +2976,12 @@ var ParaCore = class _ParaCore {
|
|
|
2779
2976
|
* @param {boolean} opts.isForNewDevice - true if this device is registering.
|
|
2780
2977
|
* @returns - transmission keyshares.
|
|
2781
2978
|
**/
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2979
|
+
getTransmissionKeyShares() {
|
|
2980
|
+
return __async(this, arguments, function* ({ isForNewDevice = false } = {}) {
|
|
2981
|
+
const res = yield this.touchSession();
|
|
2982
|
+
const sessionLookupId = isForNewDevice ? `${res.data.sessionLookupId}-new-device` : res.data.sessionLookupId;
|
|
2983
|
+
return this.ctx.client.getTransmissionKeyshares(this.userId, sessionLookupId);
|
|
2984
|
+
});
|
|
2786
2985
|
}
|
|
2787
2986
|
/**
|
|
2788
2987
|
* Call this method after login to perform setup.
|
|
@@ -2790,23 +2989,25 @@ var ParaCore = class _ParaCore {
|
|
|
2790
2989
|
* @param {any[]} opts.temporaryShares optional temporary shares to use for decryption.
|
|
2791
2990
|
* @param {boolean} [opts.skipSessionRefresh] - whether or not to skip refreshing the session.
|
|
2792
2991
|
**/
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2992
|
+
setupAfterLogin() {
|
|
2993
|
+
return __async(this, arguments, function* ({
|
|
2994
|
+
temporaryShares,
|
|
2995
|
+
skipSessionRefresh = false
|
|
2996
|
+
} = {}) {
|
|
2997
|
+
if (!temporaryShares) {
|
|
2998
|
+
temporaryShares = (yield this.getTransmissionKeyShares()).data.temporaryShares;
|
|
2999
|
+
}
|
|
3000
|
+
temporaryShares.forEach((share) => {
|
|
3001
|
+
const signer = decryptWithPrivateKey(this.loginEncryptionKeyPair.privateKey, share.encryptedShare, share.encryptedKey);
|
|
3002
|
+
this.wallets[share.walletId] = {
|
|
3003
|
+
id: share.walletId,
|
|
3004
|
+
signer
|
|
3005
|
+
};
|
|
3006
|
+
});
|
|
3007
|
+
yield this.deleteLoginEncryptionKeyPair();
|
|
3008
|
+
yield this.populateWalletAddresses();
|
|
3009
|
+
yield this.touchSession(!skipSessionRefresh);
|
|
2806
3010
|
});
|
|
2807
|
-
await this.deleteLoginEncryptionKeyPair();
|
|
2808
|
-
await this.populateWalletAddresses();
|
|
2809
|
-
await this.touchSession(!skipSessionRefresh);
|
|
2810
3011
|
}
|
|
2811
3012
|
/**
|
|
2812
3013
|
* Distributes a new wallet recovery share.
|
|
@@ -2817,51 +3018,55 @@ var ParaCore = class _ParaCore {
|
|
|
2817
3018
|
* @param {boolean} opts.forceRefreshRecovery whether or not to force recovery secret regeneration. Used when regenerating recovery shares.
|
|
2818
3019
|
* @returns {string} the recovery share.
|
|
2819
3020
|
**/
|
|
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,
|
|
3021
|
+
distributeNewWalletShare(_0) {
|
|
3022
|
+
return __async(this, arguments, function* ({
|
|
2833
3023
|
walletId,
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
forceRefresh
|
|
2837
|
-
})
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
3024
|
+
userShare,
|
|
3025
|
+
skipBiometricShareCreation = false,
|
|
3026
|
+
forceRefresh = false
|
|
3027
|
+
}) {
|
|
3028
|
+
let userSigner = userShare;
|
|
3029
|
+
if (!userSigner) {
|
|
3030
|
+
userSigner = this.wallets[walletId].signer;
|
|
3031
|
+
}
|
|
3032
|
+
const recoveryShare = skipBiometricShareCreation ? yield sendRecoveryForShare({
|
|
3033
|
+
ctx: this.ctx,
|
|
3034
|
+
userId: this.userId,
|
|
3035
|
+
walletId,
|
|
3036
|
+
userSigner,
|
|
3037
|
+
emailProps: this.getBackupKitEmailProps(),
|
|
3038
|
+
forceRefresh
|
|
3039
|
+
}) : yield distributeNewShare({
|
|
3040
|
+
ctx: this.ctx,
|
|
3041
|
+
userId: this.userId,
|
|
3042
|
+
walletId,
|
|
3043
|
+
userShare: userSigner,
|
|
3044
|
+
emailProps: this.getBackupKitEmailProps()
|
|
3045
|
+
});
|
|
3046
|
+
return recoveryShare;
|
|
2843
3047
|
});
|
|
2844
|
-
return recoveryShare;
|
|
2845
3048
|
}
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
3049
|
+
waitForWalletAddress(walletId) {
|
|
3050
|
+
return __async(this, null, function* () {
|
|
3051
|
+
let maxPolls = 0;
|
|
3052
|
+
while (true) {
|
|
3053
|
+
try {
|
|
3054
|
+
if (maxPolls === 10) {
|
|
3055
|
+
break;
|
|
3056
|
+
}
|
|
3057
|
+
++maxPolls;
|
|
3058
|
+
const res = yield this.ctx.client.getWallets(this.userId);
|
|
3059
|
+
const wallet = res.data.wallets.find((w) => w.id === walletId);
|
|
3060
|
+
if (wallet && wallet.address) {
|
|
3061
|
+
return;
|
|
3062
|
+
}
|
|
3063
|
+
yield new Promise((resolve) => setTimeout(resolve, SHORT_POLLING_INTERVAL_MS));
|
|
3064
|
+
} catch (err) {
|
|
3065
|
+
console.error(err);
|
|
2858
3066
|
}
|
|
2859
|
-
await new Promise((resolve) => setTimeout(resolve, SHORT_POLLING_INTERVAL_MS));
|
|
2860
|
-
} catch (err) {
|
|
2861
|
-
console.error(err);
|
|
2862
3067
|
}
|
|
2863
|
-
|
|
2864
|
-
|
|
3068
|
+
throw new Error("timed out waiting for wallet address");
|
|
3069
|
+
});
|
|
2865
3070
|
}
|
|
2866
3071
|
/**
|
|
2867
3072
|
* Waits for a pregen wallet address to be created.
|
|
@@ -2871,25 +3076,27 @@ var ParaCore = class _ParaCore {
|
|
|
2871
3076
|
* @param pregenIdentifierType - the identifier type of the user the pregen wallet is associated with.
|
|
2872
3077
|
* @returns - recovery share.
|
|
2873
3078
|
**/
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
3079
|
+
waitForPregenWalletAddress(walletId) {
|
|
3080
|
+
return __async(this, null, function* () {
|
|
3081
|
+
let maxPolls = 0;
|
|
3082
|
+
while (true) {
|
|
3083
|
+
try {
|
|
3084
|
+
if (maxPolls === 10) {
|
|
3085
|
+
break;
|
|
3086
|
+
}
|
|
3087
|
+
++maxPolls;
|
|
3088
|
+
const res = yield this.getPregenWallets();
|
|
3089
|
+
const wallet = res.find((w) => w.id === walletId);
|
|
3090
|
+
if (wallet && wallet.address) {
|
|
3091
|
+
return;
|
|
3092
|
+
}
|
|
3093
|
+
yield new Promise((resolve) => setTimeout(resolve, SHORT_POLLING_INTERVAL_MS));
|
|
3094
|
+
} catch (err) {
|
|
3095
|
+
console.error(err);
|
|
2886
3096
|
}
|
|
2887
|
-
await new Promise((resolve) => setTimeout(resolve, SHORT_POLLING_INTERVAL_MS));
|
|
2888
|
-
} catch (err) {
|
|
2889
|
-
console.error(err);
|
|
2890
3097
|
}
|
|
2891
|
-
|
|
2892
|
-
|
|
3098
|
+
throw new Error("timed out waiting for wallet address");
|
|
3099
|
+
});
|
|
2893
3100
|
}
|
|
2894
3101
|
/**
|
|
2895
3102
|
* Creates several new wallets with the desired types. If no types are provided, this method
|
|
@@ -2902,24 +3109,26 @@ var ParaCore = class _ParaCore {
|
|
|
2902
3109
|
* @param {WalletType[]} [opts.types] the types of wallets to create.
|
|
2903
3110
|
* @returns {Object} the wallets created, their ids, and the recovery secret.
|
|
2904
3111
|
**/
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
const
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
3112
|
+
createWalletPerType() {
|
|
3113
|
+
return __async(this, arguments, function* ({
|
|
3114
|
+
skipDistribute = false,
|
|
3115
|
+
types
|
|
3116
|
+
} = {}) {
|
|
3117
|
+
const wallets = [];
|
|
3118
|
+
const walletIds = {};
|
|
3119
|
+
let recoverySecret;
|
|
3120
|
+
for (const type of yield this.getTypesToCreate(types)) {
|
|
3121
|
+
const [wallet, recoveryShare] = yield this.createWallet({ type, skipDistribute });
|
|
3122
|
+
wallets.push(wallet);
|
|
3123
|
+
getEquivalentTypes(type).filter((t) => !!this.isWalletTypeEnabled[t]).forEach((t) => {
|
|
3124
|
+
walletIds[t] = [wallet.id];
|
|
3125
|
+
});
|
|
3126
|
+
if (recoveryShare) {
|
|
3127
|
+
recoverySecret = recoveryShare;
|
|
3128
|
+
}
|
|
2920
3129
|
}
|
|
2921
|
-
|
|
2922
|
-
|
|
3130
|
+
return { wallets, walletIds, recoverySecret };
|
|
3131
|
+
});
|
|
2923
3132
|
}
|
|
2924
3133
|
/**
|
|
2925
3134
|
* Refresh the current user share for a wallet.
|
|
@@ -2933,35 +3142,37 @@ var ParaCore = class _ParaCore {
|
|
|
2933
3142
|
* @param {boolean} [opts.redistributeBackupEncryptedShares] whether or not to redistribute backup encrypted shares.
|
|
2934
3143
|
* @returns {Object} the new user share and recovery secret.
|
|
2935
3144
|
**/
|
|
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,
|
|
3145
|
+
refreshShare(_0) {
|
|
3146
|
+
return __async(this, arguments, function* ({
|
|
2948
3147
|
walletId,
|
|
2949
3148
|
share,
|
|
2950
3149
|
oldPartnerId,
|
|
2951
3150
|
newPartnerId,
|
|
2952
|
-
keyShareProtocolId
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
3151
|
+
keyShareProtocolId,
|
|
3152
|
+
redistributeBackupEncryptedShares
|
|
3153
|
+
}) {
|
|
3154
|
+
const { signer, protocolId } = yield this.platformUtils.refresh(
|
|
3155
|
+
this.ctx,
|
|
3156
|
+
this.retrieveSessionCookie(),
|
|
3157
|
+
this.userId,
|
|
3158
|
+
walletId,
|
|
3159
|
+
share,
|
|
3160
|
+
oldPartnerId,
|
|
3161
|
+
newPartnerId,
|
|
3162
|
+
keyShareProtocolId
|
|
3163
|
+
);
|
|
3164
|
+
const recoverySecret = yield distributeNewShare({
|
|
3165
|
+
ctx: this.ctx,
|
|
3166
|
+
userId: this.userId,
|
|
3167
|
+
walletId,
|
|
3168
|
+
userShare: signer,
|
|
3169
|
+
ignoreRedistributingBackupEncryptedShare: !redistributeBackupEncryptedShares,
|
|
3170
|
+
emailProps: this.getBackupKitEmailProps(),
|
|
3171
|
+
partnerId: newPartnerId,
|
|
3172
|
+
protocolId
|
|
3173
|
+
});
|
|
3174
|
+
return { signer, recoverySecret, protocolId };
|
|
2963
3175
|
});
|
|
2964
|
-
return { signer, recoverySecret, protocolId };
|
|
2965
3176
|
}
|
|
2966
3177
|
/**
|
|
2967
3178
|
* Creates a new wallet.
|
|
@@ -2970,71 +3181,73 @@ var ParaCore = class _ParaCore {
|
|
|
2970
3181
|
* @param {boolean} opts.skipDistribute - if true, recovery share will not be distributed.
|
|
2971
3182
|
* @returns {[Wallet, string | null]} `[wallet, recoveryShare]` - the wallet object and the new recovery share.
|
|
2972
3183
|
**/
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
this.
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
3184
|
+
createWallet() {
|
|
3185
|
+
return __async(this, arguments, function* ({
|
|
3186
|
+
type: _type,
|
|
3187
|
+
skipDistribute = false
|
|
3188
|
+
} = {}) {
|
|
3189
|
+
var _a, _b;
|
|
3190
|
+
this.requireApiKey();
|
|
3191
|
+
const walletType = yield this.assertIsValidWalletType(
|
|
3192
|
+
_type != null ? _type : (_a = this.supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type
|
|
3193
|
+
);
|
|
3194
|
+
let signer;
|
|
3195
|
+
let wallet;
|
|
3196
|
+
let keygenRes;
|
|
3197
|
+
switch (walletType) {
|
|
3198
|
+
case import_user_management_client5.WalletType.SOLANA: {
|
|
3199
|
+
keygenRes = yield this.platformUtils.ed25519Keygen(
|
|
3200
|
+
this.ctx,
|
|
3201
|
+
this.userId,
|
|
3202
|
+
this.retrieveSessionCookie(),
|
|
3203
|
+
this.getBackupKitEmailProps()
|
|
3204
|
+
);
|
|
3205
|
+
break;
|
|
3206
|
+
}
|
|
3207
|
+
default: {
|
|
3208
|
+
keygenRes = yield this.platformUtils.keygen(
|
|
3209
|
+
this.ctx,
|
|
3210
|
+
this.userId,
|
|
3211
|
+
walletType,
|
|
3212
|
+
null,
|
|
3213
|
+
this.retrieveSessionCookie(),
|
|
3214
|
+
this.getBackupKitEmailProps()
|
|
3215
|
+
);
|
|
3216
|
+
break;
|
|
3217
|
+
}
|
|
2993
3218
|
}
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3219
|
+
const walletId = keygenRes.walletId;
|
|
3220
|
+
signer = keygenRes.signer;
|
|
3221
|
+
this.wallets[walletId] = {
|
|
3222
|
+
id: walletId,
|
|
3223
|
+
signer,
|
|
3224
|
+
scheme: walletType === import_user_management_client5.WalletType.SOLANA ? import_user_management_client5.WalletScheme.ED25519 : import_user_management_client5.WalletScheme.DKLS,
|
|
3225
|
+
type: walletType
|
|
3226
|
+
};
|
|
3227
|
+
wallet = this.wallets[walletId];
|
|
3228
|
+
yield this.waitForWalletAddress(wallet.id);
|
|
3229
|
+
yield this.populateWalletAddresses();
|
|
3230
|
+
let recoveryShare = null;
|
|
3231
|
+
if (!skipDistribute) {
|
|
3232
|
+
recoveryShare = yield distributeNewShare({
|
|
3233
|
+
ctx: this.ctx,
|
|
3234
|
+
userId: this.userId,
|
|
3235
|
+
walletId: wallet.id,
|
|
3236
|
+
userShare: signer,
|
|
3237
|
+
emailProps: this.getBackupKitEmailProps()
|
|
3238
|
+
});
|
|
3004
3239
|
}
|
|
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()
|
|
3240
|
+
yield this.setCurrentWalletIds(__spreadProps(__spreadValues({}, this.currentWalletIds), {
|
|
3241
|
+
[walletType]: [...(_b = this.currentWalletIds[walletType]) != null ? _b : [], walletId]
|
|
3242
|
+
}));
|
|
3243
|
+
const walletNoSigner = __spreadValues({}, wallet);
|
|
3244
|
+
delete walletNoSigner.signer;
|
|
3245
|
+
dispatchEvent(ParaEvent.WALLET_CREATED, {
|
|
3246
|
+
wallet: walletNoSigner,
|
|
3247
|
+
recoverySecret: recoveryShare
|
|
3025
3248
|
});
|
|
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
|
|
3249
|
+
return [wallet, recoveryShare];
|
|
3036
3250
|
});
|
|
3037
|
-
return [wallet, recoveryShare];
|
|
3038
3251
|
}
|
|
3039
3252
|
/**
|
|
3040
3253
|
* Creates a new pregenerated wallet.
|
|
@@ -3045,51 +3258,54 @@ var ParaCore = class _ParaCore {
|
|
|
3045
3258
|
* @param {WalletType} [opts.type] the type of wallet to create. Defaults to the first non-optional type in the instance's `supportedWalletTypes` array.
|
|
3046
3259
|
* @returns {Wallet} the created wallet.
|
|
3047
3260
|
**/
|
|
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
|
-
|
|
3261
|
+
createPregenWallet(opts) {
|
|
3262
|
+
return __async(this, null, function* () {
|
|
3263
|
+
var _a, _b;
|
|
3264
|
+
const {
|
|
3265
|
+
type: _type = (_a = this.supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type,
|
|
3266
|
+
pregenIdentifier,
|
|
3267
|
+
pregenIdentifierType = "EMAIL"
|
|
3268
|
+
} = opts;
|
|
3269
|
+
this.requireApiKey();
|
|
3270
|
+
const walletType = yield this.assertIsValidWalletType(
|
|
3271
|
+
_type != null ? _type : (_b = this.supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _b.type
|
|
3272
|
+
);
|
|
3273
|
+
let keygenRes;
|
|
3274
|
+
switch (walletType) {
|
|
3275
|
+
case import_user_management_client5.WalletType.SOLANA:
|
|
3276
|
+
keygenRes = yield this.platformUtils.ed25519PreKeygen(
|
|
3277
|
+
this.ctx,
|
|
3278
|
+
pregenIdentifier,
|
|
3279
|
+
pregenIdentifierType,
|
|
3280
|
+
this.retrieveSessionCookie()
|
|
3281
|
+
);
|
|
3282
|
+
break;
|
|
3283
|
+
default:
|
|
3284
|
+
keygenRes = yield this.platformUtils.preKeygen(
|
|
3285
|
+
this.ctx,
|
|
3286
|
+
void 0,
|
|
3287
|
+
pregenIdentifier,
|
|
3288
|
+
pregenIdentifierType,
|
|
3289
|
+
walletType,
|
|
3290
|
+
null,
|
|
3291
|
+
this.retrieveSessionCookie()
|
|
3292
|
+
);
|
|
3293
|
+
break;
|
|
3294
|
+
}
|
|
3295
|
+
const { signer, walletId } = keygenRes;
|
|
3296
|
+
this.wallets[walletId] = {
|
|
3297
|
+
id: walletId,
|
|
3298
|
+
signer,
|
|
3299
|
+
scheme: walletType === import_user_management_client5.WalletType.SOLANA ? import_user_management_client5.WalletScheme.ED25519 : import_user_management_client5.WalletScheme.DKLS,
|
|
3300
|
+
type: walletType,
|
|
3301
|
+
isPregen: true,
|
|
3302
|
+
pregenIdentifier,
|
|
3303
|
+
pregenIdentifierType
|
|
3304
|
+
};
|
|
3305
|
+
yield this.waitForPregenWalletAddress(walletId);
|
|
3306
|
+
yield this.populatePregenWalletAddresses();
|
|
3307
|
+
return this.wallets[walletId];
|
|
3308
|
+
});
|
|
3093
3309
|
}
|
|
3094
3310
|
/**
|
|
3095
3311
|
* Creates new pregenerated wallets for each desired type.
|
|
@@ -3101,17 +3317,19 @@ var ParaCore = class _ParaCore {
|
|
|
3101
3317
|
* @param {WalletType[]} [opts.types] the wallet types to create. Defaults to any types the instance supports that are not already present.
|
|
3102
3318
|
* @returns {Wallet[]} an array containing the created wallets.
|
|
3103
3319
|
**/
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
const
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3320
|
+
createPregenWalletPerType(_0) {
|
|
3321
|
+
return __async(this, arguments, function* ({
|
|
3322
|
+
types,
|
|
3323
|
+
pregenIdentifier,
|
|
3324
|
+
pregenIdentifierType = "EMAIL"
|
|
3325
|
+
}) {
|
|
3326
|
+
const wallets = [];
|
|
3327
|
+
for (const type of yield this.getTypesToCreate(types)) {
|
|
3328
|
+
const wallet = yield this.createPregenWallet({ type, pregenIdentifier, pregenIdentifierType });
|
|
3329
|
+
wallets.push(wallet);
|
|
3330
|
+
}
|
|
3331
|
+
return wallets;
|
|
3332
|
+
});
|
|
3115
3333
|
}
|
|
3116
3334
|
/**
|
|
3117
3335
|
* Claims a pregenerated wallet.
|
|
@@ -3121,63 +3339,65 @@ var ParaCore = class _ParaCore {
|
|
|
3121
3339
|
* @param {TPregenIdentifierType} opts.pregenIdentifierType type of the identifier of the user claiming the wallet
|
|
3122
3340
|
* @returns {[Wallet, string | null]} `[wallet, recoveryShare]` - the wallet object and the new recovery share.
|
|
3123
3341
|
**/
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
walletIds
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3342
|
+
claimPregenWallets() {
|
|
3343
|
+
return __async(this, arguments, function* ({
|
|
3344
|
+
pregenIdentifier,
|
|
3345
|
+
pregenIdentifierType = !!pregenIdentifier ? "EMAIL" : void 0
|
|
3346
|
+
} = {}) {
|
|
3347
|
+
var _a;
|
|
3348
|
+
this.requireApiKey();
|
|
3349
|
+
const pregenWallets = pregenIdentifier && pregenIdentifierType ? yield this.getPregenWallets({ pregenIdentifier, pregenIdentifierType }) : yield this.getPregenWallets();
|
|
3350
|
+
if (pregenWallets.length === 0) {
|
|
3351
|
+
return void 0;
|
|
3352
|
+
}
|
|
3353
|
+
let newRecoverySecret;
|
|
3354
|
+
const { walletIds } = yield this.ctx.client.claimPregenWallets({
|
|
3355
|
+
userId: this.userId,
|
|
3356
|
+
walletIds: pregenWallets.map((w) => w.id)
|
|
3357
|
+
});
|
|
3358
|
+
for (const walletId of walletIds) {
|
|
3359
|
+
const wallet = this.wallets[walletId];
|
|
3360
|
+
let refreshedShare;
|
|
3361
|
+
if (wallet.scheme === import_user_management_client5.WalletScheme.ED25519) {
|
|
3362
|
+
const distributeRes = yield distributeNewShare({
|
|
3363
|
+
ctx: this.ctx,
|
|
3364
|
+
userId: this.userId,
|
|
3365
|
+
walletId: wallet.id,
|
|
3366
|
+
userShare: this.wallets[wallet.id].signer,
|
|
3367
|
+
emailProps: this.getBackupKitEmailProps(),
|
|
3368
|
+
partnerId: wallet.partnerId
|
|
3369
|
+
});
|
|
3370
|
+
if (distributeRes.length > 0) {
|
|
3371
|
+
newRecoverySecret = distributeRes;
|
|
3372
|
+
}
|
|
3373
|
+
} else {
|
|
3374
|
+
refreshedShare = yield this.refreshShare({
|
|
3375
|
+
walletId: wallet.id,
|
|
3376
|
+
share: this.wallets[wallet.id].signer,
|
|
3377
|
+
oldPartnerId: wallet.partnerId,
|
|
3378
|
+
newPartnerId: wallet.partnerId,
|
|
3379
|
+
redistributeBackupEncryptedShares: true
|
|
3380
|
+
});
|
|
3381
|
+
if (refreshedShare.recoverySecret) {
|
|
3382
|
+
newRecoverySecret = refreshedShare.recoverySecret;
|
|
3383
|
+
}
|
|
3384
|
+
}
|
|
3385
|
+
this.wallets[wallet.id] = __spreadProps(__spreadValues({}, this.wallets[wallet.id]), {
|
|
3386
|
+
signer: (_a = refreshedShare == null ? void 0 : refreshedShare.signer) != null ? _a : wallet.signer,
|
|
3144
3387
|
userId: this.userId,
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
emailProps: this.getBackupKitEmailProps(),
|
|
3148
|
-
partnerId: wallet.partnerId
|
|
3388
|
+
pregenIdentifier: void 0,
|
|
3389
|
+
pregenIdentifierType: void 0
|
|
3149
3390
|
});
|
|
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
|
|
3391
|
+
const walletNoSigner = __spreadValues({}, this.wallets[wallet.id]);
|
|
3392
|
+
delete walletNoSigner.signer;
|
|
3393
|
+
dispatchEvent(ParaEvent.PREGEN_WALLET_CLAIMED, {
|
|
3394
|
+
wallet: walletNoSigner,
|
|
3395
|
+
recoverySecret: newRecoverySecret
|
|
3160
3396
|
});
|
|
3161
|
-
if (refreshedShare.recoverySecret) {
|
|
3162
|
-
newRecoverySecret = refreshedShare.recoverySecret;
|
|
3163
|
-
}
|
|
3164
3397
|
}
|
|
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;
|
|
3398
|
+
yield this.setWallets(this.wallets);
|
|
3399
|
+
return newRecoverySecret;
|
|
3400
|
+
});
|
|
3181
3401
|
}
|
|
3182
3402
|
/**
|
|
3183
3403
|
* Updates the identifier for a pregen wallet.
|
|
@@ -3186,24 +3406,25 @@ var ParaCore = class _ParaCore {
|
|
|
3186
3406
|
* @param {string} opts.newPregenIdentifier the new identtifier
|
|
3187
3407
|
* @param {TPregenIdentifierType} opts.newPregenIdentifierType: the new identifier type
|
|
3188
3408
|
**/
|
|
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],
|
|
3409
|
+
updatePregenWalletIdentifier(_0) {
|
|
3410
|
+
return __async(this, arguments, function* ({
|
|
3411
|
+
walletId,
|
|
3412
|
+
newPregenIdentifier,
|
|
3413
|
+
newPregenIdentifierType
|
|
3414
|
+
}) {
|
|
3415
|
+
this.requireApiKey();
|
|
3416
|
+
yield this.ctx.client.updatePregenWallet(walletId, {
|
|
3202
3417
|
pregenIdentifier: newPregenIdentifier,
|
|
3203
3418
|
pregenIdentifierType: newPregenIdentifierType
|
|
3204
|
-
};
|
|
3205
|
-
|
|
3206
|
-
|
|
3419
|
+
});
|
|
3420
|
+
if (!!this.wallets[walletId]) {
|
|
3421
|
+
this.wallets[walletId] = __spreadProps(__spreadValues({}, this.wallets[walletId]), {
|
|
3422
|
+
pregenIdentifier: newPregenIdentifier,
|
|
3423
|
+
pregenIdentifierType: newPregenIdentifierType
|
|
3424
|
+
});
|
|
3425
|
+
yield this.setWallets(this.wallets);
|
|
3426
|
+
}
|
|
3427
|
+
});
|
|
3207
3428
|
}
|
|
3208
3429
|
/**
|
|
3209
3430
|
* Checks if a pregen Wallet exists for the given identifier with the current partner.
|
|
@@ -3212,17 +3433,19 @@ var ParaCore = class _ParaCore {
|
|
|
3212
3433
|
* @param {TPregenIdentifierType} opts.pregenIdentifierType type of the string of the identifier of the user claiming the wallet
|
|
3213
3434
|
* @returns {boolean} whether the pregen wallet exists
|
|
3214
3435
|
**/
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3436
|
+
hasPregenWallet(_0) {
|
|
3437
|
+
return __async(this, arguments, function* ({
|
|
3438
|
+
pregenIdentifier,
|
|
3439
|
+
pregenIdentifierType
|
|
3440
|
+
}) {
|
|
3441
|
+
this.requireApiKey();
|
|
3442
|
+
const res = yield this.getPregenWallets({ pregenIdentifier, pregenIdentifierType });
|
|
3443
|
+
const wallet = res.find((w) => w.pregenIdentifier === pregenIdentifier && w.pregenIdentifierType === pregenIdentifierType);
|
|
3444
|
+
if (!wallet) {
|
|
3445
|
+
return false;
|
|
3446
|
+
}
|
|
3447
|
+
return true;
|
|
3448
|
+
});
|
|
3226
3449
|
}
|
|
3227
3450
|
/**
|
|
3228
3451
|
* Get pregen wallets for the given identifier.
|
|
@@ -3231,17 +3454,19 @@ var ParaCore = class _ParaCore {
|
|
|
3231
3454
|
* @param {TPregenIdentifierType} opts.pregenIdentifierType - type of the identifier of the user claiming the wallet
|
|
3232
3455
|
* @returns {Promise<WalletEntity[]>} the array of found wallets
|
|
3233
3456
|
**/
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3457
|
+
getPregenWallets() {
|
|
3458
|
+
return __async(this, arguments, function* ({
|
|
3459
|
+
pregenIdentifier,
|
|
3460
|
+
pregenIdentifierType = !!pregenIdentifier ? "EMAIL" : void 0
|
|
3461
|
+
} = {}) {
|
|
3462
|
+
this.requireApiKey();
|
|
3463
|
+
const res = yield this.ctx.client.getPregenWallets(
|
|
3464
|
+
pregenIdentifier && pregenIdentifierType ? { [pregenIdentifierType]: [pregenIdentifier] } : this.pregenIds,
|
|
3465
|
+
this.isPortal(),
|
|
3466
|
+
this.userId
|
|
3467
|
+
);
|
|
3468
|
+
return res.wallets.filter((w) => this.isWalletSupported(entityToWallet(w)));
|
|
3469
|
+
});
|
|
3245
3470
|
}
|
|
3246
3471
|
encodeWalletBase64(wallet) {
|
|
3247
3472
|
const walletJson = JSON.stringify(wallet);
|
|
@@ -3262,45 +3487,54 @@ var ParaCore = class _ParaCore {
|
|
|
3262
3487
|
* Sets the current wallets from a Base 64 string.
|
|
3263
3488
|
* @param {string} base64Wallet the encoded wallet string
|
|
3264
3489
|
**/
|
|
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()
|
|
3490
|
+
setUserShare(base64Wallets) {
|
|
3491
|
+
return __async(this, null, function* () {
|
|
3492
|
+
if (!base64Wallets) {
|
|
3493
|
+
return;
|
|
3494
|
+
}
|
|
3495
|
+
const base64WalletsSplit = base64Wallets.split("-");
|
|
3496
|
+
for (const base64Wallet of base64WalletsSplit) {
|
|
3497
|
+
const walletJson = Buffer.from(base64Wallet, "base64").toString();
|
|
3498
|
+
const wallet = migrateWallet(JSON.parse(walletJson));
|
|
3499
|
+
this.wallets[wallet.id] = wallet;
|
|
3500
|
+
yield this.setWallets(this.wallets);
|
|
3285
3501
|
}
|
|
3286
3502
|
});
|
|
3287
3503
|
}
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3504
|
+
getTransactionReviewUrl(transactionId, timeoutMs) {
|
|
3505
|
+
return __async(this, null, function* () {
|
|
3506
|
+
const res = yield this.touchSession();
|
|
3507
|
+
return this.constructPortalUrl("txReview", {
|
|
3508
|
+
partnerId: res.data.partnerId,
|
|
3509
|
+
pathId: transactionId,
|
|
3510
|
+
params: {
|
|
3511
|
+
email: this.email,
|
|
3512
|
+
timeoutMs: timeoutMs == null ? void 0 : timeoutMs.toString()
|
|
3513
|
+
}
|
|
3514
|
+
});
|
|
3515
|
+
});
|
|
3516
|
+
}
|
|
3517
|
+
getOnRampTransactionUrl(_i) {
|
|
3518
|
+
return __async(this, null, function* () {
|
|
3519
|
+
var _j = _i, {
|
|
3520
|
+
purchaseId,
|
|
3521
|
+
providerKey
|
|
3522
|
+
} = _j, walletParams = __objRest(_j, [
|
|
3523
|
+
"purchaseId",
|
|
3524
|
+
"providerKey"
|
|
3525
|
+
]);
|
|
3526
|
+
const res = yield this.touchSession();
|
|
3527
|
+
const [key, identifier] = (0, import_user_management_client5.extractWalletRef)(walletParams);
|
|
3528
|
+
return this.constructPortalUrl("onRamp", {
|
|
3529
|
+
partnerId: res.data.partnerId,
|
|
3530
|
+
pathId: purchaseId,
|
|
3531
|
+
sessionId: res.data.sessionId,
|
|
3532
|
+
params: {
|
|
3533
|
+
[key]: identifier,
|
|
3534
|
+
providerKey,
|
|
3535
|
+
currentWalletIds: JSON.stringify(this.currentWalletIds)
|
|
3536
|
+
}
|
|
3537
|
+
});
|
|
3304
3538
|
});
|
|
3305
3539
|
}
|
|
3306
3540
|
/**
|
|
@@ -3314,91 +3548,95 @@ var ParaCore = class _ParaCore {
|
|
|
3314
3548
|
* @param {number} [opts.timeout] optional timeout in milliseconds. If not present, defaults to 30 seconds.
|
|
3315
3549
|
* @param {string} [opts.cosmosSignDocBase64] the Cosmos `SignDoc` in base64, if applicable
|
|
3316
3550
|
**/
|
|
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;
|
|
3551
|
+
signMessage(_0) {
|
|
3552
|
+
return __async(this, arguments, function* ({
|
|
3553
|
+
walletId,
|
|
3554
|
+
messageBase64,
|
|
3555
|
+
timeoutMs = 3e4,
|
|
3556
|
+
cosmosSignDocBase64
|
|
3557
|
+
}) {
|
|
3558
|
+
this.assertIsValidWalletId(walletId);
|
|
3559
|
+
const wallet = this.wallets[walletId];
|
|
3560
|
+
let signerId = this.userId;
|
|
3561
|
+
if (wallet.partnerId && !wallet.userId) {
|
|
3562
|
+
signerId = wallet.partnerId;
|
|
3351
3563
|
}
|
|
3352
|
-
signRes =
|
|
3564
|
+
let signRes = yield this.signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64 });
|
|
3565
|
+
let timeStart = Date.now();
|
|
3353
3566
|
if (signRes.pendingTransactionId) {
|
|
3354
|
-
|
|
3567
|
+
this.platformUtils.openPopup(
|
|
3568
|
+
yield this.getTransactionReviewUrl(signRes.pendingTransactionId, timeoutMs),
|
|
3569
|
+
{ type: cosmosSignDocBase64 ? "SIGN_TRANSACTION_REVIEW" /* SIGN_TRANSACTION_REVIEW */ : "SIGN_MESSAGE_REVIEW" /* SIGN_MESSAGE_REVIEW */ }
|
|
3570
|
+
);
|
|
3355
3571
|
} else {
|
|
3356
|
-
|
|
3572
|
+
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes);
|
|
3573
|
+
return signRes;
|
|
3357
3574
|
}
|
|
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
|
|
3575
|
+
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
3576
|
+
while (true) {
|
|
3577
|
+
if (Date.now() - timeStart > timeoutMs) {
|
|
3578
|
+
break;
|
|
3579
|
+
}
|
|
3580
|
+
try {
|
|
3581
|
+
yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
|
|
3582
|
+
} catch (err) {
|
|
3583
|
+
const error = new TransactionReviewDenied();
|
|
3584
|
+
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes, error.message);
|
|
3585
|
+
throw error;
|
|
3586
|
+
}
|
|
3587
|
+
signRes = yield this.signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64 });
|
|
3588
|
+
if (signRes.pendingTransactionId) {
|
|
3589
|
+
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
3590
|
+
} else {
|
|
3591
|
+
break;
|
|
3592
|
+
}
|
|
3593
|
+
}
|
|
3594
|
+
if (signRes.pendingTransactionId) {
|
|
3595
|
+
const error = new TransactionReviewTimeout(
|
|
3596
|
+
yield this.getTransactionReviewUrl(signRes.pendingTransactionId),
|
|
3597
|
+
signRes.pendingTransactionId
|
|
3398
3598
|
);
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3599
|
+
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes, error.message);
|
|
3600
|
+
throw error;
|
|
3601
|
+
}
|
|
3602
|
+
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes);
|
|
3603
|
+
return signRes;
|
|
3604
|
+
});
|
|
3605
|
+
}
|
|
3606
|
+
signMessageInner(_0) {
|
|
3607
|
+
return __async(this, arguments, function* ({
|
|
3608
|
+
wallet,
|
|
3609
|
+
signerId,
|
|
3610
|
+
messageBase64,
|
|
3611
|
+
cosmosSignDocBase64
|
|
3612
|
+
}) {
|
|
3613
|
+
let signRes;
|
|
3614
|
+
switch (wallet.scheme) {
|
|
3615
|
+
case import_user_management_client5.WalletScheme.ED25519:
|
|
3616
|
+
signRes = yield this.platformUtils.ed25519Sign(
|
|
3617
|
+
this.ctx,
|
|
3618
|
+
signerId,
|
|
3619
|
+
wallet.id,
|
|
3620
|
+
wallet.signer,
|
|
3621
|
+
messageBase64,
|
|
3622
|
+
this.retrieveSessionCookie()
|
|
3623
|
+
);
|
|
3624
|
+
break;
|
|
3625
|
+
default:
|
|
3626
|
+
signRes = yield this.platformUtils.signMessage(
|
|
3627
|
+
this.ctx,
|
|
3628
|
+
signerId,
|
|
3629
|
+
wallet.id,
|
|
3630
|
+
wallet.signer,
|
|
3631
|
+
messageBase64,
|
|
3632
|
+
this.retrieveSessionCookie(),
|
|
3633
|
+
wallet.scheme === import_user_management_client5.WalletScheme.DKLS,
|
|
3634
|
+
cosmosSignDocBase64
|
|
3635
|
+
);
|
|
3636
|
+
break;
|
|
3637
|
+
}
|
|
3638
|
+
return signRes;
|
|
3639
|
+
});
|
|
3402
3640
|
}
|
|
3403
3641
|
/**
|
|
3404
3642
|
* Signs a transaction.
|
|
@@ -3408,51 +3646,20 @@ var ParaCore = class _ParaCore {
|
|
|
3408
3646
|
* @param {string} [opts.chainId] the EVM chain id of the chain the transaction is being sent on, if applicable
|
|
3409
3647
|
* @param {number} [opts.timeoutMs] the amount of time to wait for the user to sign the transaction, in milliseconds
|
|
3410
3648
|
**/
|
|
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,
|
|
3649
|
+
signTransaction(_0) {
|
|
3650
|
+
return __async(this, arguments, function* ({
|
|
3426
3651
|
walletId,
|
|
3427
|
-
this.wallets[walletId].signer,
|
|
3428
3652
|
rlpEncodedTxBase64,
|
|
3429
3653
|
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;
|
|
3654
|
+
timeoutMs = 3e4
|
|
3655
|
+
}) {
|
|
3656
|
+
this.assertIsValidWalletId(walletId);
|
|
3657
|
+
const wallet = this.wallets[walletId];
|
|
3658
|
+
let signerId = this.userId;
|
|
3659
|
+
if (wallet.partnerId && !wallet.userId) {
|
|
3660
|
+
signerId = wallet.partnerId;
|
|
3454
3661
|
}
|
|
3455
|
-
signRes =
|
|
3662
|
+
let signRes = yield this.platformUtils.signTransaction(
|
|
3456
3663
|
this.ctx,
|
|
3457
3664
|
signerId,
|
|
3458
3665
|
walletId,
|
|
@@ -3462,22 +3669,55 @@ var ParaCore = class _ParaCore {
|
|
|
3462
3669
|
this.retrieveSessionCookie(),
|
|
3463
3670
|
wallet.scheme === import_user_management_client5.WalletScheme.DKLS
|
|
3464
3671
|
);
|
|
3672
|
+
let timeStart = Date.now();
|
|
3465
3673
|
if (signRes.pendingTransactionId) {
|
|
3466
|
-
|
|
3674
|
+
this.platformUtils.openPopup(
|
|
3675
|
+
yield this.getTransactionReviewUrl(signRes.pendingTransactionId, timeoutMs),
|
|
3676
|
+
{ type: "SIGN_TRANSACTION_REVIEW" /* SIGN_TRANSACTION_REVIEW */ }
|
|
3677
|
+
);
|
|
3467
3678
|
} else {
|
|
3468
|
-
|
|
3679
|
+
dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes);
|
|
3680
|
+
return signRes;
|
|
3469
3681
|
}
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3682
|
+
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
3683
|
+
while (true) {
|
|
3684
|
+
if (Date.now() - timeStart > timeoutMs) {
|
|
3685
|
+
break;
|
|
3686
|
+
}
|
|
3687
|
+
try {
|
|
3688
|
+
yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
|
|
3689
|
+
} catch (err) {
|
|
3690
|
+
const error = new TransactionReviewDenied();
|
|
3691
|
+
dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes, error.message);
|
|
3692
|
+
throw error;
|
|
3693
|
+
}
|
|
3694
|
+
signRes = yield this.platformUtils.signTransaction(
|
|
3695
|
+
this.ctx,
|
|
3696
|
+
signerId,
|
|
3697
|
+
walletId,
|
|
3698
|
+
this.wallets[walletId].signer,
|
|
3699
|
+
rlpEncodedTxBase64,
|
|
3700
|
+
chainId,
|
|
3701
|
+
this.retrieveSessionCookie(),
|
|
3702
|
+
wallet.scheme === import_user_management_client5.WalletScheme.DKLS
|
|
3703
|
+
);
|
|
3704
|
+
if (signRes.pendingTransactionId) {
|
|
3705
|
+
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
3706
|
+
} else {
|
|
3707
|
+
break;
|
|
3708
|
+
}
|
|
3709
|
+
}
|
|
3710
|
+
if (signRes.pendingTransactionId) {
|
|
3711
|
+
const error = new TransactionReviewTimeout(
|
|
3712
|
+
yield this.getTransactionReviewUrl(signRes.pendingTransactionId),
|
|
3713
|
+
signRes.pendingTransactionId
|
|
3714
|
+
);
|
|
3715
|
+
dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes, error.message);
|
|
3716
|
+
throw error;
|
|
3717
|
+
}
|
|
3718
|
+
dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes);
|
|
3719
|
+
return signRes;
|
|
3720
|
+
});
|
|
3481
3721
|
}
|
|
3482
3722
|
/**
|
|
3483
3723
|
* @deprecated
|
|
@@ -3486,34 +3726,36 @@ var ParaCore = class _ParaCore {
|
|
|
3486
3726
|
* @param rlpEncodedTxBase64 - rlp encoded tx as base64 string
|
|
3487
3727
|
* @param chainId - chain id of the chain the transaction is being sent on.
|
|
3488
3728
|
**/
|
|
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,
|
|
3729
|
+
sendTransaction(_0) {
|
|
3730
|
+
return __async(this, arguments, function* ({
|
|
3499
3731
|
walletId,
|
|
3500
|
-
this.wallets[walletId].signer,
|
|
3501
3732
|
rlpEncodedTxBase64,
|
|
3502
|
-
chainId
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3733
|
+
chainId
|
|
3734
|
+
}) {
|
|
3735
|
+
this.assertIsValidWalletId(walletId);
|
|
3736
|
+
const wallet = this.wallets[walletId];
|
|
3737
|
+
const signRes = yield this.platformUtils.sendTransaction(
|
|
3738
|
+
this.ctx,
|
|
3739
|
+
this.userId,
|
|
3740
|
+
walletId,
|
|
3741
|
+
this.wallets[walletId].signer,
|
|
3742
|
+
rlpEncodedTxBase64,
|
|
3743
|
+
chainId,
|
|
3744
|
+
this.retrieveSessionCookie(),
|
|
3745
|
+
wallet.scheme === import_user_management_client5.WalletScheme.DKLS
|
|
3513
3746
|
);
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3747
|
+
if (signRes.pendingTransactionId) {
|
|
3748
|
+
this.platformUtils.openPopup(
|
|
3749
|
+
yield this.getTransactionReviewUrl(signRes.pendingTransactionId),
|
|
3750
|
+
{ type: "SIGN_TRANSACTION_REVIEW" /* SIGN_TRANSACTION_REVIEW */ }
|
|
3751
|
+
);
|
|
3752
|
+
const error = new TransactionReviewError(
|
|
3753
|
+
yield this.getTransactionReviewUrl(signRes.pendingTransactionId)
|
|
3754
|
+
);
|
|
3755
|
+
throw error;
|
|
3756
|
+
}
|
|
3757
|
+
return signRes;
|
|
3758
|
+
});
|
|
3517
3759
|
}
|
|
3518
3760
|
isProviderModalDisabled() {
|
|
3519
3761
|
return !!this.disableProviderModal;
|
|
@@ -3526,36 +3768,38 @@ var ParaCore = class _ParaCore {
|
|
|
3526
3768
|
* @param {string} opts.walletId the wallet ID to use for the transaction, where funds will be sent or withdrawn.
|
|
3527
3769
|
* @param {string} opts.externalWalletAddress the external wallet address to send funds to or withdraw funds from, if using an external wallet.
|
|
3528
3770
|
**/
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3771
|
+
initiateOnRampTransaction(options) {
|
|
3772
|
+
return __async(this, null, function* () {
|
|
3773
|
+
var _b;
|
|
3774
|
+
const _a = options, { params, shouldOpenPopup } = _a, walletParams = __objRest(_a, ["params", "shouldOpenPopup"]);
|
|
3775
|
+
const onRampPurchase = yield this.ctx.client.createOnRampPurchase(__spreadValues({
|
|
3776
|
+
userId: this.userId,
|
|
3777
|
+
params: __spreadProps(__spreadValues({}, params), {
|
|
3778
|
+
address: (_b = walletParams.externalWalletAddress) != null ? _b : this.getDisplayAddress(walletParams.walletId, { addressType: params.walletType })
|
|
3779
|
+
})
|
|
3780
|
+
}, walletParams));
|
|
3781
|
+
const portalUrl = yield this.getOnRampTransactionUrl(__spreadValues({
|
|
3782
|
+
purchaseId: onRampPurchase.id,
|
|
3783
|
+
providerKey: onRampPurchase.providerKey
|
|
3784
|
+
}, walletParams));
|
|
3785
|
+
if (shouldOpenPopup) {
|
|
3786
|
+
this.platformUtils.openPopup(portalUrl, { type: "ON_RAMP_TRANSACTION" /* ON_RAMP_TRANSACTION */ });
|
|
3787
|
+
}
|
|
3788
|
+
return { onRampPurchase, portalUrl };
|
|
3543
3789
|
});
|
|
3544
|
-
if (shouldOpenPopup) {
|
|
3545
|
-
this.platformUtils.openPopup(portalUrl, { type: "ON_RAMP_TRANSACTION" /* ON_RAMP_TRANSACTION */ });
|
|
3546
|
-
}
|
|
3547
|
-
return { onRampPurchase, portalUrl };
|
|
3548
3790
|
}
|
|
3549
3791
|
/**
|
|
3550
3792
|
* Returns `true` if session was successfully kept alive, `false` otherwise.
|
|
3551
3793
|
**/
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3794
|
+
keepSessionAlive() {
|
|
3795
|
+
return __async(this, null, function* () {
|
|
3796
|
+
try {
|
|
3797
|
+
yield this.ctx.client.keepSessionAlive(this.userId);
|
|
3798
|
+
return true;
|
|
3799
|
+
} catch (err) {
|
|
3800
|
+
return false;
|
|
3801
|
+
}
|
|
3802
|
+
});
|
|
3559
3803
|
}
|
|
3560
3804
|
/**
|
|
3561
3805
|
* Serialize the current session for import by another Para instance.
|
|
@@ -3580,34 +3824,37 @@ var ParaCore = class _ParaCore {
|
|
|
3580
3824
|
* Imports a session serialized by another Para instance.
|
|
3581
3825
|
* @param {string} serializedInstanceBase64 the serialized session
|
|
3582
3826
|
*/
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3827
|
+
importSession(serializedInstanceBase64) {
|
|
3828
|
+
return __async(this, null, function* () {
|
|
3829
|
+
var _a;
|
|
3830
|
+
const serializedInstance = Buffer.from(serializedInstanceBase64, "base64").toString("utf8");
|
|
3831
|
+
const sessionInfo = JSON.parse(serializedInstance);
|
|
3832
|
+
yield this.setEmail(sessionInfo.email);
|
|
3833
|
+
yield this.setTelegramUserId(sessionInfo.telegramUserId);
|
|
3834
|
+
yield this.setFarcasterUsername(sessionInfo.farcasterUsername);
|
|
3835
|
+
yield this.setUserId(sessionInfo.userId);
|
|
3836
|
+
yield this.setWallets(sessionInfo.wallets);
|
|
3837
|
+
yield this.setExternalWallets(sessionInfo.externalWallets || {});
|
|
3838
|
+
for (const walletId of Object.keys(this.wallets)) {
|
|
3839
|
+
if (!this.wallets[walletId].userId) {
|
|
3840
|
+
this.wallets[walletId].userId = this.userId;
|
|
3841
|
+
}
|
|
3595
3842
|
}
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3843
|
+
if (Object.keys(sessionInfo.currentWalletIds).length !== 0) {
|
|
3844
|
+
yield this.setCurrentWalletIds(sessionInfo.currentWalletIds);
|
|
3845
|
+
} else {
|
|
3846
|
+
const currentWalletIds = {};
|
|
3847
|
+
for (const walletId of Object.keys(sessionInfo.wallets)) {
|
|
3848
|
+
currentWalletIds[sessionInfo.wallets[walletId].type] = [
|
|
3849
|
+
...(_a = currentWalletIds[sessionInfo.wallets[walletId].type]) != null ? _a : [],
|
|
3850
|
+
walletId
|
|
3851
|
+
];
|
|
3852
|
+
}
|
|
3853
|
+
yield this.setCurrentWalletIds(currentWalletIds);
|
|
3606
3854
|
}
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
await this.setPhoneNumber(sessionInfo.phone, sessionInfo.countryCode);
|
|
3855
|
+
this.persistSessionCookie(sessionInfo.sessionCookie);
|
|
3856
|
+
yield this.setPhoneNumber(sessionInfo.phone, sessionInfo.countryCode);
|
|
3857
|
+
});
|
|
3611
3858
|
}
|
|
3612
3859
|
exitAccountCreation() {
|
|
3613
3860
|
this.isAwaitingAccountCreation = false;
|
|
@@ -3631,49 +3878,55 @@ var ParaCore = class _ParaCore {
|
|
|
3631
3878
|
* Retrieves a token to verify the current session.
|
|
3632
3879
|
* @returns {Promise<string>} the ID
|
|
3633
3880
|
**/
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3881
|
+
getVerificationToken() {
|
|
3882
|
+
return __async(this, null, function* () {
|
|
3883
|
+
const { data } = yield this.touchSession();
|
|
3884
|
+
return data.sessionLookupId;
|
|
3885
|
+
});
|
|
3637
3886
|
}
|
|
3638
3887
|
/**
|
|
3639
3888
|
* Logs the user out.
|
|
3640
3889
|
* @param {Object} opts the options object.
|
|
3641
3890
|
* @param {boolean} opts.clearPregenWallets if `true`, will remove all pregen wallets from storage
|
|
3642
3891
|
**/
|
|
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
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3892
|
+
logout() {
|
|
3893
|
+
return __async(this, arguments, function* ({ clearPregenWallets = false } = {}) {
|
|
3894
|
+
yield this.ctx.client.logout();
|
|
3895
|
+
yield this.clearStorage();
|
|
3896
|
+
if (!clearPregenWallets) {
|
|
3897
|
+
Object.entries(this.wallets).forEach(([id, wallet]) => {
|
|
3898
|
+
if (!wallet.pregenIdentifier) {
|
|
3899
|
+
delete this.wallets[id];
|
|
3900
|
+
}
|
|
3901
|
+
});
|
|
3902
|
+
yield this.setWallets(this.wallets);
|
|
3903
|
+
} else {
|
|
3904
|
+
this.wallets = {};
|
|
3905
|
+
}
|
|
3906
|
+
this.currentWalletIds = {};
|
|
3907
|
+
this.currentExternalWalletAddresses = void 0;
|
|
3908
|
+
this.externalWallets = {};
|
|
3909
|
+
this.loginEncryptionKeyPair = void 0;
|
|
3910
|
+
this.email = void 0;
|
|
3911
|
+
this.telegramUserId = void 0;
|
|
3912
|
+
this.phone = void 0;
|
|
3913
|
+
this.countryCode = void 0;
|
|
3914
|
+
this.userId = void 0;
|
|
3915
|
+
this.sessionCookie = void 0;
|
|
3916
|
+
dispatchEvent(ParaEvent.LOGOUT_EVENT, null);
|
|
3917
|
+
});
|
|
3918
|
+
}
|
|
3919
|
+
getSupportedCreateAuthMethods() {
|
|
3920
|
+
return __async(this, null, function* () {
|
|
3921
|
+
const res = yield this.touchSession();
|
|
3922
|
+
const partnerId = res.data.partnerId;
|
|
3923
|
+
const partnerRes = yield this.ctx.client.getPartner(partnerId);
|
|
3924
|
+
let supportedAuthMethods = /* @__PURE__ */ new Set();
|
|
3925
|
+
for (const authMethod of partnerRes.data.partner.supportedAuthMethods) {
|
|
3926
|
+
supportedAuthMethods.add(import_user_management_client5.AuthMethod[authMethod]);
|
|
3927
|
+
}
|
|
3928
|
+
return supportedAuthMethods;
|
|
3929
|
+
});
|
|
3677
3930
|
}
|
|
3678
3931
|
/**
|
|
3679
3932
|
* Converts to a string, removing sensitive data when logging this class.
|
|
@@ -3682,12 +3935,10 @@ var ParaCore = class _ParaCore {
|
|
|
3682
3935
|
**/
|
|
3683
3936
|
toString() {
|
|
3684
3937
|
const redactedWallets = Object.keys(this.wallets).reduce(
|
|
3685
|
-
(acc, walletId) => ({
|
|
3686
|
-
|
|
3687
|
-
[walletId]: {
|
|
3688
|
-
...this.wallets[walletId],
|
|
3938
|
+
(acc, walletId) => __spreadProps(__spreadValues({}, acc), {
|
|
3939
|
+
[walletId]: __spreadProps(__spreadValues({}, this.wallets[walletId]), {
|
|
3689
3940
|
signer: this.wallets[walletId].signer ? "[REDACTED]" : void 0
|
|
3690
|
-
}
|
|
3941
|
+
})
|
|
3691
3942
|
}),
|
|
3692
3943
|
{}
|
|
3693
3944
|
);
|
|
@@ -3718,6 +3969,10 @@ var ParaCore = class _ParaCore {
|
|
|
3718
3969
|
return `Para ${JSON.stringify(obj, null, 2)}`;
|
|
3719
3970
|
}
|
|
3720
3971
|
};
|
|
3972
|
+
_supportedWalletTypes = new WeakMap();
|
|
3973
|
+
_supportedWalletTypesOpt = new WeakMap();
|
|
3974
|
+
_ParaCore.version = PARA_CORE_VERSION;
|
|
3975
|
+
var ParaCore = _ParaCore;
|
|
3721
3976
|
|
|
3722
3977
|
// src/index.ts
|
|
3723
3978
|
var import_user_management_client6 = require("@getpara/user-management-client");
|