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