@getpara/core-sdk 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +1967 -1685
- package/dist/cjs/index.js.br +0 -0
- package/dist/cjs/index.js.gz +0 -0
- package/dist/cjs/package.json +3 -0
- package/dist/esm/index.js +1968 -1685
- package/dist/esm/index.js.br +0 -0
- package/dist/esm/index.js.gz +0 -0
- package/dist/esm/package.json +4 -0
- package/dist/types/ParaCore.d.ts +7 -1
- 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.
|
|
1107
|
+
var PARA_CORE_VERSION = '1.6.0';
|
|
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,42 @@ 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
|
+
});
|
|
1945
|
+
}
|
|
1946
|
+
/**
|
|
1947
|
+
* Fetches the most recent OAuth account metadata for the signed-in user.
|
|
1948
|
+
* If applicable, this will include the user's most recent metadata from their Google, Apple, Facebook, X, Discord, Farcaster, or Telegram account, the last time they signed in to your app.
|
|
1949
|
+
* @returns {Promise<AccountMetadata>} the user's account metadata.
|
|
1950
|
+
*/
|
|
1951
|
+
getAccountMetadata() {
|
|
1952
|
+
return __async(this, null, function* () {
|
|
1953
|
+
if (!(yield this.isSessionActive()) || !this.userId) {
|
|
1954
|
+
throw new Error("no signed-in user");
|
|
1955
|
+
}
|
|
1956
|
+
const {
|
|
1957
|
+
data: { partnerId }
|
|
1958
|
+
} = yield this.touchSession();
|
|
1959
|
+
const { accountMetadata } = yield this.ctx.client.getAccountMetadata(this.userId, partnerId);
|
|
1960
|
+
return accountMetadata;
|
|
1961
|
+
});
|
|
1845
1962
|
}
|
|
1846
1963
|
/**
|
|
1847
1964
|
* Validates that a wallet ID is present on the instance, usable, and matches the desired filters.
|
|
@@ -1895,6 +2012,7 @@ var ParaCore = class _ParaCore {
|
|
|
1895
2012
|
return wallet;
|
|
1896
2013
|
}
|
|
1897
2014
|
findWallet(idOrAddress, overrideType, filter = {}) {
|
|
2015
|
+
var _b, _c;
|
|
1898
2016
|
if (!idOrAddress && Object.keys(this.externalWallets).length > 0) {
|
|
1899
2017
|
return Object.values(this.externalWallets)[0];
|
|
1900
2018
|
}
|
|
@@ -1904,18 +2022,18 @@ var ParaCore = class _ParaCore {
|
|
|
1904
2022
|
try {
|
|
1905
2023
|
const walletId = this.findWalletId(idOrAddress, filter);
|
|
1906
2024
|
if (walletId && !!this.wallets[walletId]) {
|
|
1907
|
-
const { signer: _signer,
|
|
1908
|
-
const type = overrideType
|
|
1909
|
-
return {
|
|
1910
|
-
...wallet,
|
|
2025
|
+
const _a = this.wallets[walletId], { signer: _signer } = _a, wallet = __objRest(_a, ["signer"]);
|
|
2026
|
+
const type = (_c = overrideType != null ? overrideType : (_b = this.currentWalletIdsArray.find(([id]) => id === walletId)) == null ? void 0 : _b[1]) != null ? _c : wallet.type;
|
|
2027
|
+
return __spreadProps(__spreadValues({}, wallet), {
|
|
1911
2028
|
type: import_user_management_client5.WalletType[type]
|
|
1912
|
-
};
|
|
2029
|
+
});
|
|
1913
2030
|
}
|
|
1914
2031
|
} catch (e) {
|
|
1915
2032
|
return void 0;
|
|
1916
2033
|
}
|
|
1917
2034
|
}
|
|
1918
2035
|
get availableWallets() {
|
|
2036
|
+
var _a;
|
|
1919
2037
|
return [
|
|
1920
2038
|
...this.currentWalletIdsArray.map(([address, type]) => [address, type, false]).map(([id, type]) => {
|
|
1921
2039
|
const wallet = this.findWallet(id, type);
|
|
@@ -1927,7 +2045,7 @@ var ParaCore = class _ParaCore {
|
|
|
1927
2045
|
name: wallet.name
|
|
1928
2046
|
};
|
|
1929
2047
|
}).filter((obj) => obj !== null),
|
|
1930
|
-
...Object.values(this.externalWallets
|
|
2048
|
+
...Object.values((_a = this.externalWallets) != null ? _a : {})
|
|
1931
2049
|
];
|
|
1932
2050
|
}
|
|
1933
2051
|
/**
|
|
@@ -1941,61 +2059,78 @@ var ParaCore = class _ParaCore {
|
|
|
1941
2059
|
assertIsValidWalletId(walletId, condition = {}) {
|
|
1942
2060
|
this.isWalletUsable(walletId, condition, true);
|
|
1943
2061
|
}
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
2062
|
+
assertIsValidWalletType(type, walletTypes) {
|
|
2063
|
+
return __async(this, null, function* () {
|
|
2064
|
+
if (!__privateGet(this, _supportedWalletTypes)) {
|
|
2065
|
+
yield this.touchSession();
|
|
2066
|
+
}
|
|
2067
|
+
if (!type || !Object.values(import_user_management_client5.WalletType).includes(type) || !(walletTypes != null ? walletTypes : this.supportedWalletTypes.map(({ type: type2 }) => type2)).includes(type)) {
|
|
2068
|
+
throw new Error(`wallet type ${type} is not supported`);
|
|
2069
|
+
}
|
|
2070
|
+
return type;
|
|
2071
|
+
});
|
|
1952
2072
|
}
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
2073
|
+
getMissingTypes() {
|
|
2074
|
+
return __async(this, null, function* () {
|
|
2075
|
+
if (!__privateGet(this, _supportedWalletTypes)) {
|
|
2076
|
+
yield this.touchSession();
|
|
2077
|
+
}
|
|
2078
|
+
return this.supportedWalletTypes.filter(
|
|
2079
|
+
({ type: t, optional }) => !optional && Object.values(this.wallets).every((w) => !this.isWalletOwned(w) || !WalletSchemeTypeMap[w.scheme][t])
|
|
2080
|
+
).map(({ type }) => type);
|
|
2081
|
+
});
|
|
1960
2082
|
}
|
|
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;
|
|
2083
|
+
getTypesToCreate(types) {
|
|
2084
|
+
return __async(this, null, function* () {
|
|
2085
|
+
if (!__privateGet(this, _supportedWalletTypes)) {
|
|
2086
|
+
yield this.touchSession();
|
|
1971
2087
|
}
|
|
2088
|
+
return getSchemes(types != null ? types : yield this.getMissingTypes()).map((scheme) => {
|
|
2089
|
+
switch (scheme) {
|
|
2090
|
+
case import_user_management_client5.WalletScheme.ED25519:
|
|
2091
|
+
return import_user_management_client5.WalletType.SOLANA;
|
|
2092
|
+
default:
|
|
2093
|
+
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;
|
|
2094
|
+
}
|
|
2095
|
+
});
|
|
1972
2096
|
});
|
|
1973
2097
|
}
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
2098
|
+
getPartnerURL(partnerId) {
|
|
2099
|
+
return __async(this, null, function* () {
|
|
2100
|
+
const res = yield this.ctx.client.getPartner(partnerId);
|
|
2101
|
+
return res.data.partner.portalUrl;
|
|
2102
|
+
});
|
|
1977
2103
|
}
|
|
1978
2104
|
/**
|
|
1979
2105
|
* URL of the portal, which can be associated with a partner id
|
|
1980
2106
|
* @param partnerId: string - id of the partner to get the portal URL for
|
|
1981
2107
|
* @returns - portal URL
|
|
1982
2108
|
*/
|
|
1983
|
-
|
|
1984
|
-
return
|
|
2109
|
+
getPortalURL(partnerId) {
|
|
2110
|
+
return __async(this, null, function* () {
|
|
2111
|
+
return partnerId && (yield this.getPartnerURL(partnerId)) || getPortalBaseURL(this.ctx);
|
|
2112
|
+
});
|
|
1985
2113
|
}
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
2114
|
+
getWebAuthURLForCreate(_a) {
|
|
2115
|
+
return __async(this, null, function* () {
|
|
2116
|
+
var _b = _a, {
|
|
2117
|
+
webAuthId
|
|
2118
|
+
} = _b, options = __objRest(_b, [
|
|
2119
|
+
"webAuthId"
|
|
2120
|
+
]);
|
|
2121
|
+
return this.constructPortalUrl("createAuth", __spreadProps(__spreadValues({}, options), { pathId: webAuthId }));
|
|
2122
|
+
});
|
|
1991
2123
|
}
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
2124
|
+
getPasswordURLForCreate(_c) {
|
|
2125
|
+
return __async(this, null, function* () {
|
|
2126
|
+
var _d = _c, {
|
|
2127
|
+
passwordId
|
|
2128
|
+
} = _d, options = __objRest(_d, [
|
|
2129
|
+
"passwordId"
|
|
2130
|
+
]);
|
|
2131
|
+
return this.constructPortalUrl("createPassword", __spreadProps(__spreadValues({}, options), {
|
|
2132
|
+
pathId: passwordId
|
|
2133
|
+
}));
|
|
1999
2134
|
});
|
|
2000
2135
|
}
|
|
2001
2136
|
getShortUrl(compressedUrl) {
|
|
@@ -2004,35 +2139,42 @@ var ParaCore = class _ParaCore {
|
|
|
2004
2139
|
path: `/short/${compressedUrl}`
|
|
2005
2140
|
});
|
|
2006
2141
|
}
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2142
|
+
shortenLoginLink(link) {
|
|
2143
|
+
return __async(this, null, function* () {
|
|
2144
|
+
const url = yield upload(link, this.ctx.client);
|
|
2145
|
+
return this.getShortUrl(url);
|
|
2146
|
+
});
|
|
2010
2147
|
}
|
|
2011
2148
|
/**
|
|
2012
2149
|
* Generates a URL for registering a new WebAuth passkey.
|
|
2013
2150
|
* @param {GetWebAuthUrlForLoginParams} opts the options object
|
|
2014
2151
|
* @returns - the URL for creating a new passkey
|
|
2015
2152
|
*/
|
|
2016
|
-
|
|
2017
|
-
return this
|
|
2153
|
+
getWebAuthURLForLogin(opts) {
|
|
2154
|
+
return __async(this, null, function* () {
|
|
2155
|
+
return this.constructPortalUrl("loginAuth", opts);
|
|
2156
|
+
});
|
|
2018
2157
|
}
|
|
2019
2158
|
/**
|
|
2020
2159
|
* Generates a URL for registering a new user password.
|
|
2021
2160
|
* @param {GetWebAuthUrlForLoginParams} opts the options object
|
|
2022
2161
|
* @returns - the URL for creating a new password
|
|
2023
2162
|
*/
|
|
2024
|
-
|
|
2025
|
-
return this
|
|
2163
|
+
getPasswordURLForLogin(opts) {
|
|
2164
|
+
return __async(this, null, function* () {
|
|
2165
|
+
return this.constructPortalUrl("loginPassword", opts);
|
|
2166
|
+
});
|
|
2026
2167
|
}
|
|
2027
2168
|
/**
|
|
2028
2169
|
* Generates a URL for registering a new WebAuth passkey for a phone number.
|
|
2029
2170
|
* @param {Omit<GetWebAuthUrlForLoginParams, 'authType'>} opts the options object
|
|
2030
2171
|
* @returns - web auth url
|
|
2031
2172
|
*/
|
|
2032
|
-
|
|
2033
|
-
return this
|
|
2034
|
-
|
|
2035
|
-
|
|
2173
|
+
getWebAuthURLForLoginForPhone(opts) {
|
|
2174
|
+
return __async(this, null, function* () {
|
|
2175
|
+
return this.constructPortalUrl("loginAuth", __spreadValues({
|
|
2176
|
+
authType: "phone"
|
|
2177
|
+
}, opts));
|
|
2036
2178
|
});
|
|
2037
2179
|
}
|
|
2038
2180
|
/**
|
|
@@ -2040,57 +2182,59 @@ var ParaCore = class _ParaCore {
|
|
|
2040
2182
|
* @param {string } [walletId] id of the wallet to get the private key for. Will default to the first wallet if not provided.
|
|
2041
2183
|
* @returns - the private key string.
|
|
2042
2184
|
*/
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
this.
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2185
|
+
getPrivateKey(walletId) {
|
|
2186
|
+
return __async(this, null, function* () {
|
|
2187
|
+
const wallets = Object.values(this.wallets);
|
|
2188
|
+
const wallet = walletId ? this.wallets[walletId] : wallets == null ? void 0 : wallets[0];
|
|
2189
|
+
if (!wallet) {
|
|
2190
|
+
throw new Error("wallet not found");
|
|
2191
|
+
}
|
|
2192
|
+
if (wallet.scheme !== import_user_management_client5.WalletScheme.DKLS) {
|
|
2193
|
+
throw new Error("invalid wallet scheme");
|
|
2194
|
+
}
|
|
2195
|
+
return yield this.platformUtils.getPrivateKey(
|
|
2196
|
+
this.ctx,
|
|
2197
|
+
this.userId,
|
|
2198
|
+
wallet.id,
|
|
2199
|
+
wallet.signer,
|
|
2200
|
+
this.retrieveSessionCookie()
|
|
2201
|
+
);
|
|
2202
|
+
});
|
|
2059
2203
|
}
|
|
2060
2204
|
/**
|
|
2061
2205
|
* Fetches the wallets associated with the user.
|
|
2062
2206
|
* @returns {WalletEntity[]} wallets that were fetched.
|
|
2063
2207
|
*/
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2208
|
+
fetchWallets() {
|
|
2209
|
+
return __async(this, null, function* () {
|
|
2210
|
+
const res = yield this.isPortal() || this.isParaConnect() ? this.ctx.client.getAllWallets(this.userId) : this.ctx.client.getWallets(this.userId, true);
|
|
2211
|
+
return res.data.wallets.filter(
|
|
2212
|
+
(wallet) => !!wallet.address && (this.isParaConnect() || !this.isParaConnect() && this.isWalletSupported(entityToWallet(wallet)))
|
|
2213
|
+
);
|
|
2214
|
+
});
|
|
2069
2215
|
}
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
this.wallets[entity.id]
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2216
|
+
populateWalletAddresses() {
|
|
2217
|
+
return __async(this, null, function* () {
|
|
2218
|
+
const res = yield this.ctx.client.getWallets(this.userId, true);
|
|
2219
|
+
const wallets = res.data.wallets;
|
|
2220
|
+
wallets.forEach((entity) => {
|
|
2221
|
+
if (this.wallets[entity.id]) {
|
|
2222
|
+
this.wallets[entity.id] = __spreadValues(__spreadValues({}, entityToWallet(entity)), this.wallets[entity.id]);
|
|
2223
|
+
}
|
|
2224
|
+
});
|
|
2225
|
+
yield this.setWallets(this.wallets);
|
|
2080
2226
|
});
|
|
2081
|
-
await this.setWallets(this.wallets);
|
|
2082
2227
|
}
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
this.wallets[entity.id]
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2228
|
+
populatePregenWalletAddresses() {
|
|
2229
|
+
return __async(this, null, function* () {
|
|
2230
|
+
const res = yield this.getPregenWallets();
|
|
2231
|
+
res.forEach((entity) => {
|
|
2232
|
+
if (this.wallets[entity.id]) {
|
|
2233
|
+
this.wallets[entity.id] = __spreadValues(__spreadValues({}, entityToWallet(entity)), this.wallets[entity.id]);
|
|
2234
|
+
}
|
|
2235
|
+
});
|
|
2236
|
+
yield this.setWallets(this.wallets);
|
|
2092
2237
|
});
|
|
2093
|
-
await this.setWallets(this.wallets);
|
|
2094
2238
|
}
|
|
2095
2239
|
/**
|
|
2096
2240
|
* Checks if a user exists for an email address.
|
|
@@ -2098,9 +2242,11 @@ var ParaCore = class _ParaCore {
|
|
|
2098
2242
|
* @param {string} opts.email the email to check.
|
|
2099
2243
|
* @returns true if user exists, false otherwise.
|
|
2100
2244
|
*/
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2245
|
+
checkIfUserExists(_0) {
|
|
2246
|
+
return __async(this, arguments, function* ({ email }) {
|
|
2247
|
+
const res = yield this.ctx.client.checkUserExists({ email });
|
|
2248
|
+
return res.data.exists;
|
|
2249
|
+
});
|
|
2104
2250
|
}
|
|
2105
2251
|
/**
|
|
2106
2252
|
* Checks if a user exists for a phone number.
|
|
@@ -2109,23 +2255,26 @@ var ParaCore = class _ParaCore {
|
|
|
2109
2255
|
* @param {string} opts.countryCode - the country code.
|
|
2110
2256
|
* @returns true if user exists, false otherwise.
|
|
2111
2257
|
*/
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2258
|
+
checkIfUserExistsByPhone(_0) {
|
|
2259
|
+
return __async(this, arguments, function* ({ phone, countryCode }) {
|
|
2260
|
+
const res = yield this.ctx.client.checkUserExists({ phone, countryCode });
|
|
2261
|
+
return res.data.exists;
|
|
2262
|
+
});
|
|
2115
2263
|
}
|
|
2116
2264
|
/**
|
|
2117
2265
|
* Creates a new user.
|
|
2118
2266
|
* @param {Object} opts the options object
|
|
2119
2267
|
* @param {string} opts.email the email to use.
|
|
2120
2268
|
*/
|
|
2121
|
-
|
|
2122
|
-
this
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2269
|
+
createUser(_0) {
|
|
2270
|
+
return __async(this, arguments, function* ({ email }) {
|
|
2271
|
+
this.requireApiKey();
|
|
2272
|
+
yield this.setEmail(email);
|
|
2273
|
+
const { userId } = yield this.ctx.client.createUser(__spreadValues({
|
|
2274
|
+
email: this.email
|
|
2275
|
+
}, this.getVerificationEmailProps()));
|
|
2276
|
+
yield this.setUserId(userId);
|
|
2127
2277
|
});
|
|
2128
|
-
await this.setUserId(userId);
|
|
2129
2278
|
}
|
|
2130
2279
|
/**
|
|
2131
2280
|
* Creates a new user with a phone number.
|
|
@@ -2133,14 +2282,16 @@ var ParaCore = class _ParaCore {
|
|
|
2133
2282
|
* @param {string} opts.phone - the phone number to use for creating the user.
|
|
2134
2283
|
* @param {string} opts.countryCode - the country code to use for creating the user.
|
|
2135
2284
|
*/
|
|
2136
|
-
|
|
2137
|
-
this
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2285
|
+
createUserByPhone(_0) {
|
|
2286
|
+
return __async(this, arguments, function* ({ phone, countryCode }) {
|
|
2287
|
+
this.requireApiKey();
|
|
2288
|
+
yield this.setPhoneNumber(phone, countryCode);
|
|
2289
|
+
const { userId } = yield this.ctx.client.createUser({
|
|
2290
|
+
phone: this.phone,
|
|
2291
|
+
countryCode: this.countryCode
|
|
2292
|
+
});
|
|
2293
|
+
yield this.setUserId(userId);
|
|
2142
2294
|
});
|
|
2143
|
-
await this.setUserId(userId);
|
|
2144
2295
|
}
|
|
2145
2296
|
/**
|
|
2146
2297
|
* Logs in or creates a new user using an external wallet address.
|
|
@@ -2149,17 +2300,19 @@ var ParaCore = class _ParaCore {
|
|
|
2149
2300
|
* @param {WalletType} opts.type type of external wallet to use for identification.
|
|
2150
2301
|
* @param {string} opts.provider the name of the provider for the external wallet.
|
|
2151
2302
|
*/
|
|
2152
|
-
|
|
2153
|
-
this
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2303
|
+
externalWalletLogin(wallet) {
|
|
2304
|
+
return __async(this, null, function* () {
|
|
2305
|
+
this.requireApiKey();
|
|
2306
|
+
const res = yield this.ctx.client.externalWalletLogin({
|
|
2307
|
+
externalAddress: wallet.address,
|
|
2308
|
+
type: wallet.type,
|
|
2309
|
+
externalWalletProvider: wallet.provider,
|
|
2310
|
+
shouldTrackUser: wallet.shouldTrackUser
|
|
2311
|
+
});
|
|
2312
|
+
yield this.setExternalWallet(wallet);
|
|
2313
|
+
yield this.setUserId(res.userId);
|
|
2314
|
+
return res;
|
|
2315
|
+
});
|
|
2163
2316
|
}
|
|
2164
2317
|
/**
|
|
2165
2318
|
* Returns whether or not the user is connected with an external wallet.
|
|
@@ -2173,18 +2326,22 @@ var ParaCore = class _ParaCore {
|
|
|
2173
2326
|
* @param {string} verificationCode the six-digit code to check
|
|
2174
2327
|
* @returns {string} the web auth url for creating a new credential
|
|
2175
2328
|
*/
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2329
|
+
verifyEmail(_0) {
|
|
2330
|
+
return __async(this, arguments, function* ({ verificationCode }) {
|
|
2331
|
+
yield this.ctx.client.verifyEmail(this.userId, { verificationCode });
|
|
2332
|
+
return this.getSetUpBiometricsURL();
|
|
2333
|
+
});
|
|
2334
|
+
}
|
|
2335
|
+
verifyExternalWallet(_0) {
|
|
2336
|
+
return __async(this, arguments, function* ({
|
|
2337
|
+
address,
|
|
2338
|
+
signedMessage,
|
|
2339
|
+
cosmosPublicKeyHex,
|
|
2340
|
+
cosmosSigner
|
|
2341
|
+
}) {
|
|
2342
|
+
yield this.ctx.client.verifyExternalWallet(this.userId, { address, signedMessage, cosmosPublicKeyHex, cosmosSigner });
|
|
2343
|
+
return this.getSetUpBiometricsURL();
|
|
2344
|
+
});
|
|
2188
2345
|
}
|
|
2189
2346
|
/**
|
|
2190
2347
|
* Passes the phone code obtained from the user for verification.
|
|
@@ -2192,9 +2349,11 @@ var ParaCore = class _ParaCore {
|
|
|
2192
2349
|
* @param {string} verificationCode the six-digit code to check
|
|
2193
2350
|
* @returns {string} the web auth url for creating a new credential
|
|
2194
2351
|
*/
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2352
|
+
verifyPhone(_0) {
|
|
2353
|
+
return __async(this, arguments, function* ({ verificationCode }) {
|
|
2354
|
+
yield this.ctx.client.verifyPhone(this.userId, { verificationCode });
|
|
2355
|
+
return this.getSetUpBiometricsURLForPhone();
|
|
2356
|
+
});
|
|
2198
2357
|
}
|
|
2199
2358
|
/**
|
|
2200
2359
|
* Validates the response received from an attempted Telegram login for authenticity, then
|
|
@@ -2202,17 +2361,19 @@ var ParaCore = class _ParaCore {
|
|
|
2202
2361
|
* @param authResponse - the response JSON object received from the Telegram widget.
|
|
2203
2362
|
* @returns `{ isValid: boolean; telegramUserId?: string; userId?: string; isNewUser?: boolean; supportedAuthMethods?: AuthMethod[]; biometricHints?: BiometricLocationHint[] }`
|
|
2204
2363
|
*/
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2364
|
+
verifyTelegram(authObject) {
|
|
2365
|
+
return __async(this, null, function* () {
|
|
2366
|
+
const res = yield this.ctx.client.verifyTelegram(authObject);
|
|
2367
|
+
if (res.isValid) {
|
|
2368
|
+
yield this.setUserId(res.userId);
|
|
2369
|
+
yield this.setTelegramUserId(res.telegramUserId);
|
|
2370
|
+
yield this.touchSession(true);
|
|
2371
|
+
if (!this.loginEncryptionKeyPair) {
|
|
2372
|
+
yield this.setLoginEncryptionKeyPair();
|
|
2373
|
+
}
|
|
2213
2374
|
}
|
|
2214
|
-
|
|
2215
|
-
|
|
2375
|
+
return res;
|
|
2376
|
+
});
|
|
2216
2377
|
}
|
|
2217
2378
|
/**
|
|
2218
2379
|
* Performs 2FA verification.
|
|
@@ -2221,14 +2382,16 @@ var ParaCore = class _ParaCore {
|
|
|
2221
2382
|
* @param {string} opts.verificationCode the verification code to received via 2FA.
|
|
2222
2383
|
* @returns {Object} `{ address, initiatedAt, status, userId, walletId }`
|
|
2223
2384
|
*/
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2385
|
+
verify2FA(_0) {
|
|
2386
|
+
return __async(this, arguments, function* ({ email, verificationCode }) {
|
|
2387
|
+
const res = yield this.ctx.client.verify2FA(email, verificationCode);
|
|
2388
|
+
return {
|
|
2389
|
+
initiatedAt: res.data.initiatedAt,
|
|
2390
|
+
status: res.data.status,
|
|
2391
|
+
userId: res.data.userId,
|
|
2392
|
+
wallets: res.data.wallets
|
|
2393
|
+
};
|
|
2394
|
+
});
|
|
2232
2395
|
}
|
|
2233
2396
|
/**
|
|
2234
2397
|
* Performs 2FA verification.
|
|
@@ -2238,65 +2401,76 @@ var ParaCore = class _ParaCore {
|
|
|
2238
2401
|
* @param {string} opts.verificationCode - verification code to received via 2FA.
|
|
2239
2402
|
* @returns {Object} `{ address, initiatedAt, status, userId, walletId }`
|
|
2240
2403
|
*/
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2404
|
+
verify2FAForPhone(_0) {
|
|
2405
|
+
return __async(this, arguments, function* ({
|
|
2406
|
+
phone,
|
|
2407
|
+
countryCode,
|
|
2408
|
+
verificationCode
|
|
2409
|
+
}) {
|
|
2410
|
+
const res = yield this.ctx.client.verify2FAForPhone(phone, countryCode, verificationCode);
|
|
2411
|
+
return {
|
|
2412
|
+
initiatedAt: res.data.initiatedAt,
|
|
2413
|
+
status: res.data.status,
|
|
2414
|
+
userId: res.data.userId,
|
|
2415
|
+
wallets: res.data.wallets
|
|
2416
|
+
};
|
|
2417
|
+
});
|
|
2253
2418
|
}
|
|
2254
2419
|
/**
|
|
2255
2420
|
* Sets up two-factor authentication for the current user.
|
|
2256
2421
|
* @returns {string} uri - uri to use for setting up 2FA
|
|
2257
2422
|
* */
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2423
|
+
setup2FA() {
|
|
2424
|
+
return __async(this, null, function* () {
|
|
2425
|
+
const res = yield this.ctx.client.setup2FA(this.userId);
|
|
2426
|
+
return {
|
|
2427
|
+
uri: res.data.uri
|
|
2428
|
+
};
|
|
2429
|
+
});
|
|
2263
2430
|
}
|
|
2264
2431
|
/**
|
|
2265
2432
|
* Enables 2FA.
|
|
2266
2433
|
* @param {Object} opts the options object
|
|
2267
2434
|
* @param {string} opts.verificationCode - the verification code received via 2FA.
|
|
2268
2435
|
*/
|
|
2269
|
-
|
|
2270
|
-
|
|
2436
|
+
enable2FA(_0) {
|
|
2437
|
+
return __async(this, arguments, function* ({ verificationCode }) {
|
|
2438
|
+
yield this.ctx.client.enable2FA(this.userId, verificationCode);
|
|
2439
|
+
});
|
|
2271
2440
|
}
|
|
2272
2441
|
/**
|
|
2273
2442
|
* Determines if 2FA has been set up.
|
|
2274
2443
|
* @returns {Object} `{ isSetup: boolean }` - true if 2FA is setup, false otherwise
|
|
2275
2444
|
*/
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2445
|
+
check2FAStatus() {
|
|
2446
|
+
return __async(this, null, function* () {
|
|
2447
|
+
if (!this.userId) {
|
|
2448
|
+
return { isSetup: false };
|
|
2449
|
+
}
|
|
2450
|
+
const res = yield this.ctx.client.check2FAStatus(this.userId);
|
|
2451
|
+
return {
|
|
2452
|
+
isSetup: res.data.isSetup
|
|
2453
|
+
};
|
|
2454
|
+
});
|
|
2284
2455
|
}
|
|
2285
2456
|
/**
|
|
2286
2457
|
* Resend a verification email for the current user.
|
|
2287
2458
|
*/
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2459
|
+
resendVerificationCode() {
|
|
2460
|
+
return __async(this, null, function* () {
|
|
2461
|
+
yield this.ctx.client.resendVerificationCode(__spreadValues({
|
|
2462
|
+
userId: this.userId
|
|
2463
|
+
}, this.getVerificationEmailProps()));
|
|
2292
2464
|
});
|
|
2293
2465
|
}
|
|
2294
2466
|
/**
|
|
2295
2467
|
* Resend a verification SMS for the current user.
|
|
2296
2468
|
*/
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2469
|
+
resendVerificationCodeByPhone() {
|
|
2470
|
+
return __async(this, null, function* () {
|
|
2471
|
+
yield this.ctx.client.resendVerificationCodeByPhone({
|
|
2472
|
+
userId: this.userId
|
|
2473
|
+
});
|
|
2300
2474
|
});
|
|
2301
2475
|
}
|
|
2302
2476
|
/**
|
|
@@ -2306,19 +2480,21 @@ var ParaCore = class _ParaCore {
|
|
|
2306
2480
|
* @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
|
|
2307
2481
|
* @returns {string} the URL
|
|
2308
2482
|
*/
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2483
|
+
getSetUpBiometricsURL() {
|
|
2484
|
+
return __async(this, arguments, function* ({
|
|
2485
|
+
authType = "email",
|
|
2486
|
+
isForNewDevice = false
|
|
2487
|
+
} = {}) {
|
|
2488
|
+
const res = yield this.ctx.client.addSessionPublicKey(this.userId, {
|
|
2489
|
+
status: import_user_management_client5.PublicKeyStatus.PENDING,
|
|
2490
|
+
type: import_user_management_client5.PublicKeyType.WEB
|
|
2491
|
+
});
|
|
2492
|
+
return this.getWebAuthURLForCreate({
|
|
2493
|
+
authType,
|
|
2494
|
+
isForNewDevice,
|
|
2495
|
+
webAuthId: res.data.id,
|
|
2496
|
+
partnerId: res.data.partnerId
|
|
2497
|
+
});
|
|
2322
2498
|
});
|
|
2323
2499
|
}
|
|
2324
2500
|
/**
|
|
@@ -2327,18 +2503,20 @@ var ParaCore = class _ParaCore {
|
|
|
2327
2503
|
* @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
|
|
2328
2504
|
* @returns {string} the URL
|
|
2329
2505
|
*/
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2506
|
+
getSetUpBiometricsURLForPhone() {
|
|
2507
|
+
return __async(this, arguments, function* ({
|
|
2508
|
+
isForNewDevice = false
|
|
2509
|
+
} = {}) {
|
|
2510
|
+
const res = yield this.ctx.client.addSessionPublicKey(this.userId, {
|
|
2511
|
+
status: import_user_management_client5.PublicKeyStatus.PENDING,
|
|
2512
|
+
type: import_user_management_client5.PublicKeyType.WEB
|
|
2513
|
+
});
|
|
2514
|
+
return this.getWebAuthURLForCreate({
|
|
2515
|
+
authType: "phone",
|
|
2516
|
+
isForNewDevice,
|
|
2517
|
+
webAuthId: res.data.id,
|
|
2518
|
+
partnerId: res.data.partnerId
|
|
2519
|
+
});
|
|
2342
2520
|
});
|
|
2343
2521
|
}
|
|
2344
2522
|
/**
|
|
@@ -2349,95 +2527,107 @@ var ParaCore = class _ParaCore {
|
|
|
2349
2527
|
* @param {Theme} [opts.theme] the portal theme to use in place of the partner's default
|
|
2350
2528
|
* @returns {string} the URL
|
|
2351
2529
|
*/
|
|
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,
|
|
2530
|
+
getSetupPasswordURL() {
|
|
2531
|
+
return __async(this, arguments, function* ({
|
|
2532
|
+
authType = "email",
|
|
2533
|
+
isForNewDevice = false,
|
|
2365
2534
|
theme
|
|
2535
|
+
} = {}) {
|
|
2536
|
+
const res = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
|
|
2537
|
+
status: import_user_management_client5.PasswordStatus.PENDING
|
|
2538
|
+
});
|
|
2539
|
+
return this.getPasswordURLForCreate({
|
|
2540
|
+
authType,
|
|
2541
|
+
isForNewDevice,
|
|
2542
|
+
passwordId: res.data.id,
|
|
2543
|
+
partnerId: res.data.partnerId,
|
|
2544
|
+
theme
|
|
2545
|
+
});
|
|
2366
2546
|
});
|
|
2367
2547
|
}
|
|
2368
2548
|
/**
|
|
2369
2549
|
* Checks if the current session is active.
|
|
2370
2550
|
* @returns `true` if active, `false` otherwise
|
|
2371
2551
|
*/
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2552
|
+
isSessionActive() {
|
|
2553
|
+
return __async(this, null, function* () {
|
|
2554
|
+
if (this.isUsingExternalWallet()) {
|
|
2555
|
+
return true;
|
|
2556
|
+
}
|
|
2557
|
+
const res = yield this.touchSession();
|
|
2558
|
+
return !!res.data.isAuthenticated;
|
|
2559
|
+
});
|
|
2378
2560
|
}
|
|
2379
2561
|
/**
|
|
2380
2562
|
* Checks if a session is active and a wallet exists.
|
|
2381
2563
|
* @returns `true` if active, `false` otherwise
|
|
2382
2564
|
**/
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2565
|
+
isFullyLoggedIn() {
|
|
2566
|
+
return __async(this, null, function* () {
|
|
2567
|
+
if (this.isUsingExternalWallet()) {
|
|
2568
|
+
return true;
|
|
2569
|
+
}
|
|
2570
|
+
const isSessionActive = yield this.isSessionActive();
|
|
2571
|
+
return isSessionActive && this.currentWalletIdsArray.length > 0 && this.currentWalletIdsArray.reduce((acc, [id]) => acc && !!this.wallets[id], true);
|
|
2572
|
+
});
|
|
2389
2573
|
}
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2574
|
+
supportedAuthMethods(auth) {
|
|
2575
|
+
return __async(this, null, function* () {
|
|
2576
|
+
const { supportedAuthMethods } = yield this.ctx.client.getSupportedAuthMethods(auth);
|
|
2577
|
+
const authMethods = /* @__PURE__ */ new Set();
|
|
2578
|
+
for (const type of supportedAuthMethods) {
|
|
2579
|
+
switch (type) {
|
|
2580
|
+
case "PASSWORD":
|
|
2581
|
+
authMethods.add(import_user_management_client5.AuthMethod.PASSWORD);
|
|
2582
|
+
break;
|
|
2583
|
+
case "BIOMETRIC":
|
|
2584
|
+
authMethods.add(import_user_management_client5.AuthMethod.PASSKEY);
|
|
2585
|
+
break;
|
|
2586
|
+
}
|
|
2401
2587
|
}
|
|
2402
|
-
|
|
2403
|
-
|
|
2588
|
+
return authMethods;
|
|
2589
|
+
});
|
|
2404
2590
|
}
|
|
2405
2591
|
/**
|
|
2406
2592
|
* Get hints associated with the users stored biometrics.
|
|
2407
2593
|
* @returns Array containing useragents and AAGuids for stored biometrics
|
|
2408
2594
|
*/
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2595
|
+
getUserBiometricLocationHints() {
|
|
2596
|
+
return __async(this, null, function* () {
|
|
2597
|
+
if (!this.email && !this.phone && !this.farcasterUsername && !this.telegramUserId) {
|
|
2598
|
+
throw new Error("one of email, phone or farcaster username are required to get biometric location hints");
|
|
2599
|
+
}
|
|
2600
|
+
return yield this.ctx.client.getBiometricLocationHints({
|
|
2601
|
+
email: this.email,
|
|
2602
|
+
phone: this.phone,
|
|
2603
|
+
countryCode: this.countryCode,
|
|
2604
|
+
farcasterUsername: this.farcasterUsername,
|
|
2605
|
+
telegramUserId: this.telegramUserId
|
|
2606
|
+
});
|
|
2419
2607
|
});
|
|
2420
2608
|
}
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2609
|
+
setAuth(auth) {
|
|
2610
|
+
return __async(this, null, function* () {
|
|
2611
|
+
const authInfo = (0, import_user_management_client5.extractAuthInfo)(auth);
|
|
2612
|
+
if (!authInfo) {
|
|
2613
|
+
return void 0;
|
|
2614
|
+
}
|
|
2615
|
+
switch (authInfo.authType) {
|
|
2616
|
+
case "email":
|
|
2617
|
+
yield this.setEmail(authInfo.identifier);
|
|
2618
|
+
break;
|
|
2619
|
+
case "phone":
|
|
2620
|
+
yield this.setPhoneNumber(authInfo.auth.phone, authInfo.auth.countryCode);
|
|
2621
|
+
break;
|
|
2622
|
+
case "farcaster":
|
|
2623
|
+
yield this.setFarcasterUsername(authInfo.identifier);
|
|
2624
|
+
break;
|
|
2625
|
+
case "telegram":
|
|
2626
|
+
yield this.setTelegramUserId(authInfo.identifier);
|
|
2627
|
+
break;
|
|
2628
|
+
}
|
|
2629
|
+
return authInfo;
|
|
2630
|
+
});
|
|
2441
2631
|
}
|
|
2442
2632
|
/**
|
|
2443
2633
|
* Initiates a login.
|
|
@@ -2446,41 +2636,46 @@ var ParaCore = class _ParaCore {
|
|
|
2446
2636
|
* @param {boolean} opts.useShortURL - whether to shorten the link
|
|
2447
2637
|
* @returns - the WebAuth URL for logging in
|
|
2448
2638
|
**/
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2639
|
+
initiateUserLogin(_e) {
|
|
2640
|
+
return __async(this, null, function* () {
|
|
2641
|
+
var _f = _e, { useShortUrl = false } = _f, auth = __objRest(_f, ["useShortUrl"]);
|
|
2642
|
+
const authInfo = yield this.setAuth(auth);
|
|
2643
|
+
if (!authInfo) {
|
|
2644
|
+
return;
|
|
2645
|
+
}
|
|
2646
|
+
const res = yield this.touchSession(true);
|
|
2647
|
+
if (!this.loginEncryptionKeyPair) {
|
|
2648
|
+
yield this.setLoginEncryptionKeyPair();
|
|
2649
|
+
}
|
|
2650
|
+
const webAuthLoginURL = yield this.getWebAuthURLForLogin({
|
|
2651
|
+
authType: authInfo.authType,
|
|
2652
|
+
sessionId: res.data.sessionId,
|
|
2653
|
+
partnerId: res.data.partnerId,
|
|
2654
|
+
loginEncryptionPublicKey: getPublicKeyHex(this.loginEncryptionKeyPair)
|
|
2655
|
+
});
|
|
2656
|
+
if (!useShortUrl) {
|
|
2657
|
+
return webAuthLoginURL;
|
|
2658
|
+
}
|
|
2659
|
+
return this.shortenLoginLink(webAuthLoginURL);
|
|
2660
|
+
});
|
|
2468
2661
|
}
|
|
2469
2662
|
/**
|
|
2470
2663
|
* Initiates a login.
|
|
2471
2664
|
* @param email - the email to login with
|
|
2472
2665
|
* @returns - a set of supported auth methods for the user
|
|
2473
2666
|
**/
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2667
|
+
initiateUserLoginV2(auth) {
|
|
2668
|
+
return __async(this, null, function* () {
|
|
2669
|
+
const authInfo = yield this.setAuth(auth);
|
|
2670
|
+
if (!authInfo) {
|
|
2671
|
+
return;
|
|
2672
|
+
}
|
|
2673
|
+
yield this.touchSession(true);
|
|
2674
|
+
if (!this.loginEncryptionKeyPair) {
|
|
2675
|
+
yield this.setLoginEncryptionKeyPair();
|
|
2676
|
+
}
|
|
2677
|
+
return yield this.supportedAuthMethods(authInfo.auth);
|
|
2678
|
+
});
|
|
2484
2679
|
}
|
|
2485
2680
|
/**
|
|
2486
2681
|
* Initiates a login.
|
|
@@ -2490,112 +2685,124 @@ var ParaCore = class _ParaCore {
|
|
|
2490
2685
|
* @param opts.useShortURL - whether to shorten the link
|
|
2491
2686
|
* @returns - the WebAuth URL for logging in
|
|
2492
2687
|
**/
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2688
|
+
initiateUserLoginForPhone(_g) {
|
|
2689
|
+
return __async(this, null, function* () {
|
|
2690
|
+
var _h = _g, {
|
|
2691
|
+
useShortUrl = false
|
|
2692
|
+
} = _h, auth = __objRest(_h, [
|
|
2693
|
+
"useShortUrl"
|
|
2694
|
+
]);
|
|
2695
|
+
yield this.setAuth(auth);
|
|
2696
|
+
const res = yield this.touchSession(true);
|
|
2697
|
+
if (!this.loginEncryptionKeyPair) {
|
|
2698
|
+
yield this.setLoginEncryptionKeyPair();
|
|
2699
|
+
}
|
|
2700
|
+
const webAuthLoginURL = yield this.getWebAuthURLForLoginForPhone({
|
|
2701
|
+
sessionId: res.data.sessionId,
|
|
2702
|
+
loginEncryptionPublicKey: getPublicKeyHex(this.loginEncryptionKeyPair),
|
|
2703
|
+
partnerId: res.data.partnerId
|
|
2704
|
+
});
|
|
2705
|
+
if (!useShortUrl) {
|
|
2706
|
+
return webAuthLoginURL;
|
|
2707
|
+
}
|
|
2708
|
+
return this.shortenLoginLink(webAuthLoginURL);
|
|
2506
2709
|
});
|
|
2507
|
-
if (!useShortUrl) {
|
|
2508
|
-
return webAuthLoginURL;
|
|
2509
|
-
}
|
|
2510
|
-
return this.shortenLoginLink(webAuthLoginURL);
|
|
2511
2710
|
}
|
|
2512
2711
|
/**
|
|
2513
2712
|
* Waits for the session to be active.
|
|
2514
2713
|
**/
|
|
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) {
|
|
2714
|
+
waitForAccountCreation() {
|
|
2715
|
+
return __async(this, arguments, function* ({ popupWindow } = {}) {
|
|
2716
|
+
yield this.touchSession();
|
|
2717
|
+
this.externalWallets = {};
|
|
2718
|
+
this.isAwaitingAccountCreation = true;
|
|
2719
|
+
while (this.isAwaitingAccountCreation) {
|
|
2720
|
+
try {
|
|
2721
|
+
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
2722
|
+
if (yield this.isSessionActive()) {
|
|
2528
2723
|
this.isAwaitingAccountCreation = false;
|
|
2529
|
-
|
|
2724
|
+
dispatchEvent(ParaEvent.ACCOUNT_CREATION_EVENT, true);
|
|
2725
|
+
return true;
|
|
2726
|
+
} else {
|
|
2727
|
+
if (popupWindow == null ? void 0 : popupWindow.closed) {
|
|
2728
|
+
this.isAwaitingAccountCreation = false;
|
|
2729
|
+
return false;
|
|
2730
|
+
}
|
|
2530
2731
|
}
|
|
2732
|
+
} catch (err) {
|
|
2733
|
+
console.error(err);
|
|
2531
2734
|
}
|
|
2532
|
-
} catch (err) {
|
|
2533
|
-
console.error(err);
|
|
2534
2735
|
}
|
|
2535
|
-
|
|
2536
|
-
|
|
2736
|
+
return false;
|
|
2737
|
+
});
|
|
2537
2738
|
}
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2739
|
+
waitForPasskeyAndCreateWallet() {
|
|
2740
|
+
return __async(this, arguments, function* ({
|
|
2741
|
+
popupWindow
|
|
2742
|
+
} = {}) {
|
|
2743
|
+
yield this.waitForAccountCreation({ popupWindow });
|
|
2744
|
+
const pregenWallets = yield this.getPregenWallets();
|
|
2745
|
+
let recoverySecret, walletIds = {};
|
|
2746
|
+
if (pregenWallets.length > 0) {
|
|
2747
|
+
recoverySecret = yield this.claimPregenWallets();
|
|
2748
|
+
walletIds = this.supportedWalletTypes.reduce((acc, { type }) => {
|
|
2749
|
+
var _a;
|
|
2750
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
2751
|
+
[type]: [(_a = pregenWallets.find((w) => !!WalletSchemeTypeMap[w.scheme][type])) == null ? void 0 : _a.id]
|
|
2752
|
+
});
|
|
2753
|
+
}, {});
|
|
2754
|
+
}
|
|
2755
|
+
const created = yield this.createWalletPerType();
|
|
2756
|
+
recoverySecret = recoverySecret != null ? recoverySecret : created.recoverySecret;
|
|
2757
|
+
walletIds = __spreadValues(__spreadValues({}, walletIds), created.walletIds);
|
|
2758
|
+
const resp = { walletIds, recoverySecret };
|
|
2759
|
+
dispatchEvent(ParaEvent.ACCOUNT_SETUP_EVENT, resp);
|
|
2760
|
+
return resp;
|
|
2761
|
+
});
|
|
2559
2762
|
}
|
|
2560
2763
|
/**
|
|
2561
2764
|
* Initiates a Farcaster login attempt and return the URI for the user to connect.
|
|
2562
2765
|
* You can create a QR code with this URI that works with Farcaster's mobile app.
|
|
2563
2766
|
* @return {string} the Farcaster connect URI
|
|
2564
2767
|
*/
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2768
|
+
getFarcasterConnectURL() {
|
|
2769
|
+
return __async(this, null, function* () {
|
|
2770
|
+
yield this.logout();
|
|
2771
|
+
yield this.touchSession(true);
|
|
2772
|
+
const {
|
|
2773
|
+
data: { connect_uri }
|
|
2774
|
+
} = yield this.ctx.client.initializeFarcasterLogin();
|
|
2775
|
+
return connect_uri;
|
|
2776
|
+
});
|
|
2572
2777
|
}
|
|
2573
2778
|
/**
|
|
2574
2779
|
* Awaits the response from a user's attempt to log in with Farcaster.
|
|
2575
2780
|
* If successful, this returns the user's Farcaster username and profile picture and indicates whether the user already exists.
|
|
2576
2781
|
* @return {Object} `{userExists: boolean; username: string; pfpUrl?: string | null }` - the user's information and whether the user already exists.
|
|
2577
2782
|
*/
|
|
2578
|
-
|
|
2579
|
-
this
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2783
|
+
waitForFarcasterStatus() {
|
|
2784
|
+
return __async(this, null, function* () {
|
|
2785
|
+
this.isAwaitingFarcaster = true;
|
|
2786
|
+
while (this.isAwaitingFarcaster) {
|
|
2787
|
+
try {
|
|
2788
|
+
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
2789
|
+
const res = yield this.ctx.client.getFarcasterAuthStatus();
|
|
2790
|
+
if (res.data.state === "completed") {
|
|
2791
|
+
const { userId, userExists, username, pfpUrl } = res.data;
|
|
2792
|
+
yield this.setUserId(userId);
|
|
2793
|
+
yield this.setFarcasterUsername(username);
|
|
2794
|
+
return {
|
|
2795
|
+
userExists,
|
|
2796
|
+
username,
|
|
2797
|
+
pfpUrl
|
|
2798
|
+
};
|
|
2799
|
+
}
|
|
2800
|
+
} catch (err) {
|
|
2801
|
+
console.error(err);
|
|
2802
|
+
this.isAwaitingFarcaster = false;
|
|
2593
2803
|
}
|
|
2594
|
-
} catch (err) {
|
|
2595
|
-
console.error(err);
|
|
2596
|
-
this.isAwaitingFarcaster = false;
|
|
2597
2804
|
}
|
|
2598
|
-
}
|
|
2805
|
+
});
|
|
2599
2806
|
}
|
|
2600
2807
|
/**
|
|
2601
2808
|
* Generates a URL for the user to log in with OAuth using a desire method.
|
|
@@ -2605,17 +2812,19 @@ var ParaCore = class _ParaCore {
|
|
|
2605
2812
|
* @param {string} [opts.deeplinkUrl] the deeplink to redirect to after the OAuth flow. This is for mobile only.
|
|
2606
2813
|
* @returns {string} the URL for the user to log in with OAuth.
|
|
2607
2814
|
*/
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2815
|
+
getOAuthURL(_0) {
|
|
2816
|
+
return __async(this, arguments, function* ({ method, deeplinkUrl }) {
|
|
2817
|
+
yield this.logout();
|
|
2818
|
+
const res = yield this.touchSession(true);
|
|
2819
|
+
return constructUrl({
|
|
2820
|
+
base: method === import_user_management_client5.OAuthMethod.TELEGRAM ? getPortalBaseURL(this.ctx, true) : getBaseOAuthUrl(this.ctx.env),
|
|
2821
|
+
path: `/auth/${method.toLowerCase()}`,
|
|
2822
|
+
params: {
|
|
2823
|
+
apiKey: this.ctx.apiKey,
|
|
2824
|
+
sessionLookupId: res.data.sessionLookupId,
|
|
2825
|
+
deeplinkUrl
|
|
2826
|
+
}
|
|
2827
|
+
});
|
|
2619
2828
|
});
|
|
2620
2829
|
}
|
|
2621
2830
|
/**
|
|
@@ -2626,36 +2835,38 @@ var ParaCore = class _ParaCore {
|
|
|
2626
2835
|
* @param {Window} [opts.popupWindow] the popup window being used for login.
|
|
2627
2836
|
* @return {Object} `{ email?: string; isError?: boolean; userExists: boolean; }` the result data
|
|
2628
2837
|
*/
|
|
2629
|
-
|
|
2630
|
-
this
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2838
|
+
waitForOAuth() {
|
|
2839
|
+
return __async(this, arguments, function* ({ popupWindow } = {}) {
|
|
2840
|
+
this.isAwaitingOAuth = true;
|
|
2841
|
+
while (this.isAwaitingOAuth) {
|
|
2842
|
+
try {
|
|
2843
|
+
if (popupWindow == null ? void 0 : popupWindow.closed) {
|
|
2844
|
+
return { isError: true, userExists: false };
|
|
2845
|
+
}
|
|
2846
|
+
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
2847
|
+
if (this.isAwaitingOAuth) {
|
|
2848
|
+
const res = yield this.touchSession();
|
|
2849
|
+
if (res.data.userId) {
|
|
2850
|
+
const { userId, email } = res.data;
|
|
2851
|
+
if (!this.loginEncryptionKeyPair) {
|
|
2852
|
+
yield this.setLoginEncryptionKeyPair();
|
|
2853
|
+
}
|
|
2854
|
+
yield this.setUserId(userId);
|
|
2855
|
+
yield this.setEmail(email);
|
|
2856
|
+
const userExists = yield this.checkIfUserExists({ email });
|
|
2857
|
+
this.isAwaitingOAuth = false;
|
|
2858
|
+
return {
|
|
2859
|
+
userExists,
|
|
2860
|
+
email
|
|
2861
|
+
};
|
|
2643
2862
|
}
|
|
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
2863
|
}
|
|
2864
|
+
} catch (err) {
|
|
2865
|
+
console.error(err);
|
|
2653
2866
|
}
|
|
2654
|
-
} catch (err) {
|
|
2655
|
-
console.error(err);
|
|
2656
2867
|
}
|
|
2657
|
-
|
|
2658
|
-
|
|
2868
|
+
return { userExists: false };
|
|
2869
|
+
});
|
|
2659
2870
|
}
|
|
2660
2871
|
/**
|
|
2661
2872
|
* Waits for the session to be active and sets up the user.
|
|
@@ -2665,56 +2876,59 @@ var ParaCore = class _ParaCore {
|
|
|
2665
2876
|
* @param {boolean} [opts.skipSessionRefresh] whether to skip refreshing the session.
|
|
2666
2877
|
* @returns {Object} `{ isComplete: boolean; isError: boolean; needsWallet: boolean; partnerId: string; }` the result data
|
|
2667
2878
|
**/
|
|
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) {
|
|
2879
|
+
waitForLoginAndSetup() {
|
|
2880
|
+
return __async(this, arguments, function* ({
|
|
2881
|
+
popupWindow,
|
|
2882
|
+
skipSessionRefresh = false
|
|
2883
|
+
} = {}) {
|
|
2884
|
+
var _a;
|
|
2885
|
+
this.externalWallets = {};
|
|
2886
|
+
this.isAwaitingLogin = true;
|
|
2887
|
+
while (this.isAwaitingLogin) {
|
|
2888
|
+
try {
|
|
2889
|
+
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
2890
|
+
if (!(yield this.isSessionActive())) {
|
|
2891
|
+
if (popupWindow == null ? void 0 : popupWindow.closed) {
|
|
2690
2892
|
const resp2 = { isComplete: false, isError: true };
|
|
2691
2893
|
dispatchEvent(ParaEvent.LOGIN_EVENT, resp2, "failed to setup user");
|
|
2692
2894
|
return resp2;
|
|
2693
|
-
} else {
|
|
2694
|
-
continue;
|
|
2695
2895
|
}
|
|
2896
|
+
continue;
|
|
2696
2897
|
}
|
|
2898
|
+
const postLoginData = yield this.userSetupAfterLogin();
|
|
2899
|
+
const needsWallet = (_a = postLoginData.data.needsWallet) != null ? _a : false;
|
|
2900
|
+
if (!needsWallet) {
|
|
2901
|
+
if (this.currentWalletIdsArray.length === 0) {
|
|
2902
|
+
if (popupWindow == null ? void 0 : popupWindow.closed) {
|
|
2903
|
+
const resp2 = { isComplete: false, isError: true };
|
|
2904
|
+
dispatchEvent(ParaEvent.LOGIN_EVENT, resp2, "failed to setup user");
|
|
2905
|
+
return resp2;
|
|
2906
|
+
} else {
|
|
2907
|
+
continue;
|
|
2908
|
+
}
|
|
2909
|
+
}
|
|
2910
|
+
}
|
|
2911
|
+
const fetchedWallets = yield this.fetchWallets();
|
|
2912
|
+
const tempSharesRes = yield this.getTransmissionKeyShares();
|
|
2913
|
+
if (tempSharesRes.data.temporaryShares.length === fetchedWallets.length) {
|
|
2914
|
+
yield this.setupAfterLogin({ temporaryShares: tempSharesRes.data.temporaryShares, skipSessionRefresh });
|
|
2915
|
+
yield this.claimPregenWallets();
|
|
2916
|
+
const resp2 = {
|
|
2917
|
+
isComplete: true,
|
|
2918
|
+
needsWallet: needsWallet || Object.values(this.wallets).length === 0,
|
|
2919
|
+
partnerId: postLoginData.data.partnerId
|
|
2920
|
+
};
|
|
2921
|
+
dispatchEvent(ParaEvent.LOGIN_EVENT, resp2);
|
|
2922
|
+
return resp2;
|
|
2923
|
+
}
|
|
2924
|
+
} catch (err) {
|
|
2925
|
+
console.error(err);
|
|
2697
2926
|
}
|
|
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
2927
|
}
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2928
|
+
const resp = { isComplete: false };
|
|
2929
|
+
dispatchEvent(ParaEvent.LOGIN_EVENT, resp, "exitted login without setting up user");
|
|
2930
|
+
return resp;
|
|
2931
|
+
});
|
|
2718
2932
|
}
|
|
2719
2933
|
/**
|
|
2720
2934
|
* Updates the session with the user management server, possibly
|
|
@@ -2724,32 +2938,36 @@ var ParaCore = class _ParaCore {
|
|
|
2724
2938
|
* @param {boolean} [shouldOpenPopup] - if `true`, the running device will open a popup to reauthenticate the user.
|
|
2725
2939
|
* @returns a URL for the user to reauthenticate.
|
|
2726
2940
|
**/
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2941
|
+
refreshSession() {
|
|
2942
|
+
return __async(this, arguments, function* ({ shouldOpenPopup = false } = {}) {
|
|
2943
|
+
const res = yield this.touchSession(true);
|
|
2944
|
+
if (!this.loginEncryptionKeyPair) {
|
|
2945
|
+
yield this.setLoginEncryptionKeyPair();
|
|
2946
|
+
}
|
|
2947
|
+
const link = yield this.getWebAuthURLForLogin({
|
|
2948
|
+
sessionId: res.data.sessionId,
|
|
2949
|
+
loginEncryptionPublicKey: getPublicKeyHex(this.loginEncryptionKeyPair)
|
|
2950
|
+
});
|
|
2951
|
+
if (shouldOpenPopup) {
|
|
2952
|
+
this.platformUtils.openPopup(link);
|
|
2953
|
+
}
|
|
2954
|
+
return link;
|
|
2735
2955
|
});
|
|
2736
|
-
if (shouldOpenPopup) {
|
|
2737
|
-
this.platformUtils.openPopup(link);
|
|
2738
|
-
}
|
|
2739
|
-
return link;
|
|
2740
2956
|
}
|
|
2741
2957
|
/**
|
|
2742
2958
|
* Call this method after login to ensure that the user ID is set
|
|
2743
2959
|
* internally.
|
|
2744
2960
|
**/
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2961
|
+
userSetupAfterLogin() {
|
|
2962
|
+
return __async(this, null, function* () {
|
|
2963
|
+
const res = yield this.touchSession();
|
|
2964
|
+
yield this.setUserId(res.data.userId);
|
|
2965
|
+
if (res.data.currentWalletIds && res.data.currentWalletIds !== this.currentWalletIds)
|
|
2966
|
+
yield this.setCurrentWalletIds(res.data.currentWalletIds, {
|
|
2967
|
+
sessionLookupId: this.isPortal() ? res.data.sessionLookupId : void 0
|
|
2968
|
+
});
|
|
2969
|
+
return res;
|
|
2970
|
+
});
|
|
2753
2971
|
}
|
|
2754
2972
|
/**
|
|
2755
2973
|
* Get transmission shares associated with session.
|
|
@@ -2757,10 +2975,12 @@ var ParaCore = class _ParaCore {
|
|
|
2757
2975
|
* @param {boolean} opts.isForNewDevice - true if this device is registering.
|
|
2758
2976
|
* @returns - transmission keyshares.
|
|
2759
2977
|
**/
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2978
|
+
getTransmissionKeyShares() {
|
|
2979
|
+
return __async(this, arguments, function* ({ isForNewDevice = false } = {}) {
|
|
2980
|
+
const res = yield this.touchSession();
|
|
2981
|
+
const sessionLookupId = isForNewDevice ? `${res.data.sessionLookupId}-new-device` : res.data.sessionLookupId;
|
|
2982
|
+
return this.ctx.client.getTransmissionKeyshares(this.userId, sessionLookupId);
|
|
2983
|
+
});
|
|
2764
2984
|
}
|
|
2765
2985
|
/**
|
|
2766
2986
|
* Call this method after login to perform setup.
|
|
@@ -2768,23 +2988,25 @@ var ParaCore = class _ParaCore {
|
|
|
2768
2988
|
* @param {any[]} opts.temporaryShares optional temporary shares to use for decryption.
|
|
2769
2989
|
* @param {boolean} [opts.skipSessionRefresh] - whether or not to skip refreshing the session.
|
|
2770
2990
|
**/
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2991
|
+
setupAfterLogin() {
|
|
2992
|
+
return __async(this, arguments, function* ({
|
|
2993
|
+
temporaryShares,
|
|
2994
|
+
skipSessionRefresh = false
|
|
2995
|
+
} = {}) {
|
|
2996
|
+
if (!temporaryShares) {
|
|
2997
|
+
temporaryShares = (yield this.getTransmissionKeyShares()).data.temporaryShares;
|
|
2998
|
+
}
|
|
2999
|
+
temporaryShares.forEach((share) => {
|
|
3000
|
+
const signer = decryptWithPrivateKey(this.loginEncryptionKeyPair.privateKey, share.encryptedShare, share.encryptedKey);
|
|
3001
|
+
this.wallets[share.walletId] = {
|
|
3002
|
+
id: share.walletId,
|
|
3003
|
+
signer
|
|
3004
|
+
};
|
|
3005
|
+
});
|
|
3006
|
+
yield this.deleteLoginEncryptionKeyPair();
|
|
3007
|
+
yield this.populateWalletAddresses();
|
|
3008
|
+
yield this.touchSession(!skipSessionRefresh);
|
|
2784
3009
|
});
|
|
2785
|
-
await this.deleteLoginEncryptionKeyPair();
|
|
2786
|
-
await this.populateWalletAddresses();
|
|
2787
|
-
await this.touchSession(!skipSessionRefresh);
|
|
2788
3010
|
}
|
|
2789
3011
|
/**
|
|
2790
3012
|
* Distributes a new wallet recovery share.
|
|
@@ -2795,51 +3017,55 @@ var ParaCore = class _ParaCore {
|
|
|
2795
3017
|
* @param {boolean} opts.forceRefreshRecovery whether or not to force recovery secret regeneration. Used when regenerating recovery shares.
|
|
2796
3018
|
* @returns {string} the recovery share.
|
|
2797
3019
|
**/
|
|
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,
|
|
3020
|
+
distributeNewWalletShare(_0) {
|
|
3021
|
+
return __async(this, arguments, function* ({
|
|
2811
3022
|
walletId,
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
forceRefresh
|
|
2815
|
-
})
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
3023
|
+
userShare,
|
|
3024
|
+
skipBiometricShareCreation = false,
|
|
3025
|
+
forceRefresh = false
|
|
3026
|
+
}) {
|
|
3027
|
+
let userSigner = userShare;
|
|
3028
|
+
if (!userSigner) {
|
|
3029
|
+
userSigner = this.wallets[walletId].signer;
|
|
3030
|
+
}
|
|
3031
|
+
const recoveryShare = skipBiometricShareCreation ? yield sendRecoveryForShare({
|
|
3032
|
+
ctx: this.ctx,
|
|
3033
|
+
userId: this.userId,
|
|
3034
|
+
walletId,
|
|
3035
|
+
userSigner,
|
|
3036
|
+
emailProps: this.getBackupKitEmailProps(),
|
|
3037
|
+
forceRefresh
|
|
3038
|
+
}) : yield distributeNewShare({
|
|
3039
|
+
ctx: this.ctx,
|
|
3040
|
+
userId: this.userId,
|
|
3041
|
+
walletId,
|
|
3042
|
+
userShare: userSigner,
|
|
3043
|
+
emailProps: this.getBackupKitEmailProps()
|
|
3044
|
+
});
|
|
3045
|
+
return recoveryShare;
|
|
2821
3046
|
});
|
|
2822
|
-
return recoveryShare;
|
|
2823
3047
|
}
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
3048
|
+
waitForWalletAddress(walletId) {
|
|
3049
|
+
return __async(this, null, function* () {
|
|
3050
|
+
let maxPolls = 0;
|
|
3051
|
+
while (true) {
|
|
3052
|
+
try {
|
|
3053
|
+
if (maxPolls === 10) {
|
|
3054
|
+
break;
|
|
3055
|
+
}
|
|
3056
|
+
++maxPolls;
|
|
3057
|
+
const res = yield this.ctx.client.getWallets(this.userId);
|
|
3058
|
+
const wallet = res.data.wallets.find((w) => w.id === walletId);
|
|
3059
|
+
if (wallet && wallet.address) {
|
|
3060
|
+
return;
|
|
3061
|
+
}
|
|
3062
|
+
yield new Promise((resolve) => setTimeout(resolve, SHORT_POLLING_INTERVAL_MS));
|
|
3063
|
+
} catch (err) {
|
|
3064
|
+
console.error(err);
|
|
2836
3065
|
}
|
|
2837
|
-
await new Promise((resolve) => setTimeout(resolve, SHORT_POLLING_INTERVAL_MS));
|
|
2838
|
-
} catch (err) {
|
|
2839
|
-
console.error(err);
|
|
2840
3066
|
}
|
|
2841
|
-
|
|
2842
|
-
|
|
3067
|
+
throw new Error("timed out waiting for wallet address");
|
|
3068
|
+
});
|
|
2843
3069
|
}
|
|
2844
3070
|
/**
|
|
2845
3071
|
* Waits for a pregen wallet address to be created.
|
|
@@ -2849,25 +3075,27 @@ var ParaCore = class _ParaCore {
|
|
|
2849
3075
|
* @param pregenIdentifierType - the identifier type of the user the pregen wallet is associated with.
|
|
2850
3076
|
* @returns - recovery share.
|
|
2851
3077
|
**/
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
3078
|
+
waitForPregenWalletAddress(walletId) {
|
|
3079
|
+
return __async(this, null, function* () {
|
|
3080
|
+
let maxPolls = 0;
|
|
3081
|
+
while (true) {
|
|
3082
|
+
try {
|
|
3083
|
+
if (maxPolls === 10) {
|
|
3084
|
+
break;
|
|
3085
|
+
}
|
|
3086
|
+
++maxPolls;
|
|
3087
|
+
const res = yield this.getPregenWallets();
|
|
3088
|
+
const wallet = res.find((w) => w.id === walletId);
|
|
3089
|
+
if (wallet && wallet.address) {
|
|
3090
|
+
return;
|
|
3091
|
+
}
|
|
3092
|
+
yield new Promise((resolve) => setTimeout(resolve, SHORT_POLLING_INTERVAL_MS));
|
|
3093
|
+
} catch (err) {
|
|
3094
|
+
console.error(err);
|
|
2864
3095
|
}
|
|
2865
|
-
await new Promise((resolve) => setTimeout(resolve, SHORT_POLLING_INTERVAL_MS));
|
|
2866
|
-
} catch (err) {
|
|
2867
|
-
console.error(err);
|
|
2868
3096
|
}
|
|
2869
|
-
|
|
2870
|
-
|
|
3097
|
+
throw new Error("timed out waiting for wallet address");
|
|
3098
|
+
});
|
|
2871
3099
|
}
|
|
2872
3100
|
/**
|
|
2873
3101
|
* Creates several new wallets with the desired types. If no types are provided, this method
|
|
@@ -2880,24 +3108,26 @@ var ParaCore = class _ParaCore {
|
|
|
2880
3108
|
* @param {WalletType[]} [opts.types] the types of wallets to create.
|
|
2881
3109
|
* @returns {Object} the wallets created, their ids, and the recovery secret.
|
|
2882
3110
|
**/
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
const
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
3111
|
+
createWalletPerType() {
|
|
3112
|
+
return __async(this, arguments, function* ({
|
|
3113
|
+
skipDistribute = false,
|
|
3114
|
+
types
|
|
3115
|
+
} = {}) {
|
|
3116
|
+
const wallets = [];
|
|
3117
|
+
const walletIds = {};
|
|
3118
|
+
let recoverySecret;
|
|
3119
|
+
for (const type of yield this.getTypesToCreate(types)) {
|
|
3120
|
+
const [wallet, recoveryShare] = yield this.createWallet({ type, skipDistribute });
|
|
3121
|
+
wallets.push(wallet);
|
|
3122
|
+
getEquivalentTypes(type).filter((t) => !!this.isWalletTypeEnabled[t]).forEach((t) => {
|
|
3123
|
+
walletIds[t] = [wallet.id];
|
|
3124
|
+
});
|
|
3125
|
+
if (recoveryShare) {
|
|
3126
|
+
recoverySecret = recoveryShare;
|
|
3127
|
+
}
|
|
2898
3128
|
}
|
|
2899
|
-
|
|
2900
|
-
|
|
3129
|
+
return { wallets, walletIds, recoverySecret };
|
|
3130
|
+
});
|
|
2901
3131
|
}
|
|
2902
3132
|
/**
|
|
2903
3133
|
* Refresh the current user share for a wallet.
|
|
@@ -2911,35 +3141,37 @@ var ParaCore = class _ParaCore {
|
|
|
2911
3141
|
* @param {boolean} [opts.redistributeBackupEncryptedShares] whether or not to redistribute backup encrypted shares.
|
|
2912
3142
|
* @returns {Object} the new user share and recovery secret.
|
|
2913
3143
|
**/
|
|
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,
|
|
3144
|
+
refreshShare(_0) {
|
|
3145
|
+
return __async(this, arguments, function* ({
|
|
2926
3146
|
walletId,
|
|
2927
3147
|
share,
|
|
2928
3148
|
oldPartnerId,
|
|
2929
3149
|
newPartnerId,
|
|
2930
|
-
keyShareProtocolId
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
3150
|
+
keyShareProtocolId,
|
|
3151
|
+
redistributeBackupEncryptedShares
|
|
3152
|
+
}) {
|
|
3153
|
+
const { signer, protocolId } = yield this.platformUtils.refresh(
|
|
3154
|
+
this.ctx,
|
|
3155
|
+
this.retrieveSessionCookie(),
|
|
3156
|
+
this.userId,
|
|
3157
|
+
walletId,
|
|
3158
|
+
share,
|
|
3159
|
+
oldPartnerId,
|
|
3160
|
+
newPartnerId,
|
|
3161
|
+
keyShareProtocolId
|
|
3162
|
+
);
|
|
3163
|
+
const recoverySecret = yield distributeNewShare({
|
|
3164
|
+
ctx: this.ctx,
|
|
3165
|
+
userId: this.userId,
|
|
3166
|
+
walletId,
|
|
3167
|
+
userShare: signer,
|
|
3168
|
+
ignoreRedistributingBackupEncryptedShare: !redistributeBackupEncryptedShares,
|
|
3169
|
+
emailProps: this.getBackupKitEmailProps(),
|
|
3170
|
+
partnerId: newPartnerId,
|
|
3171
|
+
protocolId
|
|
3172
|
+
});
|
|
3173
|
+
return { signer, recoverySecret, protocolId };
|
|
2941
3174
|
});
|
|
2942
|
-
return { signer, recoverySecret, protocolId };
|
|
2943
3175
|
}
|
|
2944
3176
|
/**
|
|
2945
3177
|
* Creates a new wallet.
|
|
@@ -2948,71 +3180,73 @@ var ParaCore = class _ParaCore {
|
|
|
2948
3180
|
* @param {boolean} opts.skipDistribute - if true, recovery share will not be distributed.
|
|
2949
3181
|
* @returns {[Wallet, string | null]} `[wallet, recoveryShare]` - the wallet object and the new recovery share.
|
|
2950
3182
|
**/
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
this.
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
3183
|
+
createWallet() {
|
|
3184
|
+
return __async(this, arguments, function* ({
|
|
3185
|
+
type: _type,
|
|
3186
|
+
skipDistribute = false
|
|
3187
|
+
} = {}) {
|
|
3188
|
+
var _a, _b;
|
|
3189
|
+
this.requireApiKey();
|
|
3190
|
+
const walletType = yield this.assertIsValidWalletType(
|
|
3191
|
+
_type != null ? _type : (_a = this.supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type
|
|
3192
|
+
);
|
|
3193
|
+
let signer;
|
|
3194
|
+
let wallet;
|
|
3195
|
+
let keygenRes;
|
|
3196
|
+
switch (walletType) {
|
|
3197
|
+
case import_user_management_client5.WalletType.SOLANA: {
|
|
3198
|
+
keygenRes = yield this.platformUtils.ed25519Keygen(
|
|
3199
|
+
this.ctx,
|
|
3200
|
+
this.userId,
|
|
3201
|
+
this.retrieveSessionCookie(),
|
|
3202
|
+
this.getBackupKitEmailProps()
|
|
3203
|
+
);
|
|
3204
|
+
break;
|
|
3205
|
+
}
|
|
3206
|
+
default: {
|
|
3207
|
+
keygenRes = yield this.platformUtils.keygen(
|
|
3208
|
+
this.ctx,
|
|
3209
|
+
this.userId,
|
|
3210
|
+
walletType,
|
|
3211
|
+
null,
|
|
3212
|
+
this.retrieveSessionCookie(),
|
|
3213
|
+
this.getBackupKitEmailProps()
|
|
3214
|
+
);
|
|
3215
|
+
break;
|
|
3216
|
+
}
|
|
2971
3217
|
}
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
3218
|
+
const walletId = keygenRes.walletId;
|
|
3219
|
+
signer = keygenRes.signer;
|
|
3220
|
+
this.wallets[walletId] = {
|
|
3221
|
+
id: walletId,
|
|
3222
|
+
signer,
|
|
3223
|
+
scheme: walletType === import_user_management_client5.WalletType.SOLANA ? import_user_management_client5.WalletScheme.ED25519 : import_user_management_client5.WalletScheme.DKLS,
|
|
3224
|
+
type: walletType
|
|
3225
|
+
};
|
|
3226
|
+
wallet = this.wallets[walletId];
|
|
3227
|
+
yield this.waitForWalletAddress(wallet.id);
|
|
3228
|
+
yield this.populateWalletAddresses();
|
|
3229
|
+
let recoveryShare = null;
|
|
3230
|
+
if (!skipDistribute) {
|
|
3231
|
+
recoveryShare = yield distributeNewShare({
|
|
3232
|
+
ctx: this.ctx,
|
|
3233
|
+
userId: this.userId,
|
|
3234
|
+
walletId: wallet.id,
|
|
3235
|
+
userShare: signer,
|
|
3236
|
+
emailProps: this.getBackupKitEmailProps()
|
|
3237
|
+
});
|
|
2982
3238
|
}
|
|
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()
|
|
3239
|
+
yield this.setCurrentWalletIds(__spreadProps(__spreadValues({}, this.currentWalletIds), {
|
|
3240
|
+
[walletType]: [...(_b = this.currentWalletIds[walletType]) != null ? _b : [], walletId]
|
|
3241
|
+
}));
|
|
3242
|
+
const walletNoSigner = __spreadValues({}, wallet);
|
|
3243
|
+
delete walletNoSigner.signer;
|
|
3244
|
+
dispatchEvent(ParaEvent.WALLET_CREATED, {
|
|
3245
|
+
wallet: walletNoSigner,
|
|
3246
|
+
recoverySecret: recoveryShare
|
|
3003
3247
|
});
|
|
3004
|
-
|
|
3005
|
-
await this.setCurrentWalletIds({
|
|
3006
|
-
...this.currentWalletIds,
|
|
3007
|
-
[walletType]: [...this.currentWalletIds[walletType] ?? [], walletId]
|
|
3008
|
-
});
|
|
3009
|
-
const walletNoSigner = { ...wallet };
|
|
3010
|
-
delete walletNoSigner.signer;
|
|
3011
|
-
dispatchEvent(ParaEvent.WALLET_CREATED, {
|
|
3012
|
-
wallet: walletNoSigner,
|
|
3013
|
-
recoverySecret: recoveryShare
|
|
3248
|
+
return [wallet, recoveryShare];
|
|
3014
3249
|
});
|
|
3015
|
-
return [wallet, recoveryShare];
|
|
3016
3250
|
}
|
|
3017
3251
|
/**
|
|
3018
3252
|
* Creates a new pregenerated wallet.
|
|
@@ -3023,51 +3257,54 @@ var ParaCore = class _ParaCore {
|
|
|
3023
3257
|
* @param {WalletType} [opts.type] the type of wallet to create. Defaults to the first non-optional type in the instance's `supportedWalletTypes` array.
|
|
3024
3258
|
* @returns {Wallet} the created wallet.
|
|
3025
3259
|
**/
|
|
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
|
-
|
|
3260
|
+
createPregenWallet(opts) {
|
|
3261
|
+
return __async(this, null, function* () {
|
|
3262
|
+
var _a, _b;
|
|
3263
|
+
const {
|
|
3264
|
+
type: _type = (_a = this.supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type,
|
|
3265
|
+
pregenIdentifier,
|
|
3266
|
+
pregenIdentifierType = "EMAIL"
|
|
3267
|
+
} = opts;
|
|
3268
|
+
this.requireApiKey();
|
|
3269
|
+
const walletType = yield this.assertIsValidWalletType(
|
|
3270
|
+
_type != null ? _type : (_b = this.supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _b.type
|
|
3271
|
+
);
|
|
3272
|
+
let keygenRes;
|
|
3273
|
+
switch (walletType) {
|
|
3274
|
+
case import_user_management_client5.WalletType.SOLANA:
|
|
3275
|
+
keygenRes = yield this.platformUtils.ed25519PreKeygen(
|
|
3276
|
+
this.ctx,
|
|
3277
|
+
pregenIdentifier,
|
|
3278
|
+
pregenIdentifierType,
|
|
3279
|
+
this.retrieveSessionCookie()
|
|
3280
|
+
);
|
|
3281
|
+
break;
|
|
3282
|
+
default:
|
|
3283
|
+
keygenRes = yield this.platformUtils.preKeygen(
|
|
3284
|
+
this.ctx,
|
|
3285
|
+
void 0,
|
|
3286
|
+
pregenIdentifier,
|
|
3287
|
+
pregenIdentifierType,
|
|
3288
|
+
walletType,
|
|
3289
|
+
null,
|
|
3290
|
+
this.retrieveSessionCookie()
|
|
3291
|
+
);
|
|
3292
|
+
break;
|
|
3293
|
+
}
|
|
3294
|
+
const { signer, walletId } = keygenRes;
|
|
3295
|
+
this.wallets[walletId] = {
|
|
3296
|
+
id: walletId,
|
|
3297
|
+
signer,
|
|
3298
|
+
scheme: walletType === import_user_management_client5.WalletType.SOLANA ? import_user_management_client5.WalletScheme.ED25519 : import_user_management_client5.WalletScheme.DKLS,
|
|
3299
|
+
type: walletType,
|
|
3300
|
+
isPregen: true,
|
|
3301
|
+
pregenIdentifier,
|
|
3302
|
+
pregenIdentifierType
|
|
3303
|
+
};
|
|
3304
|
+
yield this.waitForPregenWalletAddress(walletId);
|
|
3305
|
+
yield this.populatePregenWalletAddresses();
|
|
3306
|
+
return this.wallets[walletId];
|
|
3307
|
+
});
|
|
3071
3308
|
}
|
|
3072
3309
|
/**
|
|
3073
3310
|
* Creates new pregenerated wallets for each desired type.
|
|
@@ -3079,17 +3316,19 @@ var ParaCore = class _ParaCore {
|
|
|
3079
3316
|
* @param {WalletType[]} [opts.types] the wallet types to create. Defaults to any types the instance supports that are not already present.
|
|
3080
3317
|
* @returns {Wallet[]} an array containing the created wallets.
|
|
3081
3318
|
**/
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
const
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3319
|
+
createPregenWalletPerType(_0) {
|
|
3320
|
+
return __async(this, arguments, function* ({
|
|
3321
|
+
types,
|
|
3322
|
+
pregenIdentifier,
|
|
3323
|
+
pregenIdentifierType = "EMAIL"
|
|
3324
|
+
}) {
|
|
3325
|
+
const wallets = [];
|
|
3326
|
+
for (const type of yield this.getTypesToCreate(types)) {
|
|
3327
|
+
const wallet = yield this.createPregenWallet({ type, pregenIdentifier, pregenIdentifierType });
|
|
3328
|
+
wallets.push(wallet);
|
|
3329
|
+
}
|
|
3330
|
+
return wallets;
|
|
3331
|
+
});
|
|
3093
3332
|
}
|
|
3094
3333
|
/**
|
|
3095
3334
|
* Claims a pregenerated wallet.
|
|
@@ -3099,63 +3338,71 @@ var ParaCore = class _ParaCore {
|
|
|
3099
3338
|
* @param {TPregenIdentifierType} opts.pregenIdentifierType type of the identifier of the user claiming the wallet
|
|
3100
3339
|
* @returns {[Wallet, string | null]} `[wallet, recoveryShare]` - the wallet object and the new recovery share.
|
|
3101
3340
|
**/
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3341
|
+
claimPregenWallets() {
|
|
3342
|
+
return __async(this, arguments, function* ({
|
|
3343
|
+
pregenIdentifier,
|
|
3344
|
+
pregenIdentifierType = !!pregenIdentifier ? "EMAIL" : void 0
|
|
3345
|
+
} = {}) {
|
|
3346
|
+
var _a;
|
|
3347
|
+
this.requireApiKey();
|
|
3348
|
+
const pregenWallets = pregenIdentifier && pregenIdentifierType ? yield this.getPregenWallets({ pregenIdentifier, pregenIdentifierType }) : yield this.getPregenWallets();
|
|
3349
|
+
if (pregenWallets.length === 0) {
|
|
3350
|
+
return void 0;
|
|
3351
|
+
}
|
|
3352
|
+
const missingWallets = pregenWallets.filter((wallet) => !this.wallets[wallet.id]);
|
|
3353
|
+
if (missingWallets.length > 0) {
|
|
3354
|
+
throw new Error(
|
|
3355
|
+
`Cannot claim pregen wallets because wallet data is missing. Please call setUserShare first to load the wallet data for the following wallet IDs: ${missingWallets.map((w) => w.id).join(", ")}`
|
|
3356
|
+
);
|
|
3357
|
+
}
|
|
3358
|
+
let newRecoverySecret;
|
|
3359
|
+
const { walletIds } = yield this.ctx.client.claimPregenWallets({
|
|
3360
|
+
userId: this.userId,
|
|
3361
|
+
walletIds: pregenWallets.map((w) => w.id)
|
|
3362
|
+
});
|
|
3363
|
+
for (const walletId of walletIds) {
|
|
3364
|
+
const wallet = this.wallets[walletId];
|
|
3365
|
+
let refreshedShare;
|
|
3366
|
+
if (wallet.scheme === import_user_management_client5.WalletScheme.ED25519) {
|
|
3367
|
+
const distributeRes = yield distributeNewShare({
|
|
3368
|
+
ctx: this.ctx,
|
|
3369
|
+
userId: this.userId,
|
|
3370
|
+
walletId: wallet.id,
|
|
3371
|
+
userShare: this.wallets[wallet.id].signer,
|
|
3372
|
+
emailProps: this.getBackupKitEmailProps(),
|
|
3373
|
+
partnerId: wallet.partnerId
|
|
3374
|
+
});
|
|
3375
|
+
if (distributeRes.length > 0) {
|
|
3376
|
+
newRecoverySecret = distributeRes;
|
|
3377
|
+
}
|
|
3378
|
+
} else {
|
|
3379
|
+
refreshedShare = yield this.refreshShare({
|
|
3380
|
+
walletId: wallet.id,
|
|
3381
|
+
share: this.wallets[wallet.id].signer,
|
|
3382
|
+
oldPartnerId: wallet.partnerId,
|
|
3383
|
+
newPartnerId: wallet.partnerId,
|
|
3384
|
+
redistributeBackupEncryptedShares: true
|
|
3385
|
+
});
|
|
3386
|
+
if (refreshedShare.recoverySecret) {
|
|
3387
|
+
newRecoverySecret = refreshedShare.recoverySecret;
|
|
3388
|
+
}
|
|
3389
|
+
}
|
|
3390
|
+
this.wallets[wallet.id] = __spreadProps(__spreadValues({}, this.wallets[wallet.id]), {
|
|
3391
|
+
signer: (_a = refreshedShare == null ? void 0 : refreshedShare.signer) != null ? _a : wallet.signer,
|
|
3122
3392
|
userId: this.userId,
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
emailProps: this.getBackupKitEmailProps(),
|
|
3126
|
-
partnerId: wallet.partnerId
|
|
3393
|
+
pregenIdentifier: void 0,
|
|
3394
|
+
pregenIdentifierType: void 0
|
|
3127
3395
|
});
|
|
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
|
|
3396
|
+
const walletNoSigner = __spreadValues({}, this.wallets[wallet.id]);
|
|
3397
|
+
delete walletNoSigner.signer;
|
|
3398
|
+
dispatchEvent(ParaEvent.PREGEN_WALLET_CLAIMED, {
|
|
3399
|
+
wallet: walletNoSigner,
|
|
3400
|
+
recoverySecret: newRecoverySecret
|
|
3138
3401
|
});
|
|
3139
|
-
if (refreshedShare.recoverySecret) {
|
|
3140
|
-
newRecoverySecret = refreshedShare.recoverySecret;
|
|
3141
|
-
}
|
|
3142
3402
|
}
|
|
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;
|
|
3403
|
+
yield this.setWallets(this.wallets);
|
|
3404
|
+
return newRecoverySecret;
|
|
3405
|
+
});
|
|
3159
3406
|
}
|
|
3160
3407
|
/**
|
|
3161
3408
|
* Updates the identifier for a pregen wallet.
|
|
@@ -3164,24 +3411,25 @@ var ParaCore = class _ParaCore {
|
|
|
3164
3411
|
* @param {string} opts.newPregenIdentifier the new identtifier
|
|
3165
3412
|
* @param {TPregenIdentifierType} opts.newPregenIdentifierType: the new identifier type
|
|
3166
3413
|
**/
|
|
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],
|
|
3414
|
+
updatePregenWalletIdentifier(_0) {
|
|
3415
|
+
return __async(this, arguments, function* ({
|
|
3416
|
+
walletId,
|
|
3417
|
+
newPregenIdentifier,
|
|
3418
|
+
newPregenIdentifierType
|
|
3419
|
+
}) {
|
|
3420
|
+
this.requireApiKey();
|
|
3421
|
+
yield this.ctx.client.updatePregenWallet(walletId, {
|
|
3180
3422
|
pregenIdentifier: newPregenIdentifier,
|
|
3181
3423
|
pregenIdentifierType: newPregenIdentifierType
|
|
3182
|
-
};
|
|
3183
|
-
|
|
3184
|
-
|
|
3424
|
+
});
|
|
3425
|
+
if (!!this.wallets[walletId]) {
|
|
3426
|
+
this.wallets[walletId] = __spreadProps(__spreadValues({}, this.wallets[walletId]), {
|
|
3427
|
+
pregenIdentifier: newPregenIdentifier,
|
|
3428
|
+
pregenIdentifierType: newPregenIdentifierType
|
|
3429
|
+
});
|
|
3430
|
+
yield this.setWallets(this.wallets);
|
|
3431
|
+
}
|
|
3432
|
+
});
|
|
3185
3433
|
}
|
|
3186
3434
|
/**
|
|
3187
3435
|
* Checks if a pregen Wallet exists for the given identifier with the current partner.
|
|
@@ -3190,17 +3438,19 @@ var ParaCore = class _ParaCore {
|
|
|
3190
3438
|
* @param {TPregenIdentifierType} opts.pregenIdentifierType type of the string of the identifier of the user claiming the wallet
|
|
3191
3439
|
* @returns {boolean} whether the pregen wallet exists
|
|
3192
3440
|
**/
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3441
|
+
hasPregenWallet(_0) {
|
|
3442
|
+
return __async(this, arguments, function* ({
|
|
3443
|
+
pregenIdentifier,
|
|
3444
|
+
pregenIdentifierType
|
|
3445
|
+
}) {
|
|
3446
|
+
this.requireApiKey();
|
|
3447
|
+
const res = yield this.getPregenWallets({ pregenIdentifier, pregenIdentifierType });
|
|
3448
|
+
const wallet = res.find((w) => w.pregenIdentifier === pregenIdentifier && w.pregenIdentifierType === pregenIdentifierType);
|
|
3449
|
+
if (!wallet) {
|
|
3450
|
+
return false;
|
|
3451
|
+
}
|
|
3452
|
+
return true;
|
|
3453
|
+
});
|
|
3204
3454
|
}
|
|
3205
3455
|
/**
|
|
3206
3456
|
* Get pregen wallets for the given identifier.
|
|
@@ -3209,17 +3459,19 @@ var ParaCore = class _ParaCore {
|
|
|
3209
3459
|
* @param {TPregenIdentifierType} opts.pregenIdentifierType - type of the identifier of the user claiming the wallet
|
|
3210
3460
|
* @returns {Promise<WalletEntity[]>} the array of found wallets
|
|
3211
3461
|
**/
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3462
|
+
getPregenWallets() {
|
|
3463
|
+
return __async(this, arguments, function* ({
|
|
3464
|
+
pregenIdentifier,
|
|
3465
|
+
pregenIdentifierType = !!pregenIdentifier ? "EMAIL" : void 0
|
|
3466
|
+
} = {}) {
|
|
3467
|
+
this.requireApiKey();
|
|
3468
|
+
const res = yield this.ctx.client.getPregenWallets(
|
|
3469
|
+
pregenIdentifier && pregenIdentifierType ? { [pregenIdentifierType]: [pregenIdentifier] } : this.pregenIds,
|
|
3470
|
+
this.isPortal(),
|
|
3471
|
+
this.userId
|
|
3472
|
+
);
|
|
3473
|
+
return res.wallets.filter((w) => this.isWalletSupported(entityToWallet(w)));
|
|
3474
|
+
});
|
|
3223
3475
|
}
|
|
3224
3476
|
encodeWalletBase64(wallet) {
|
|
3225
3477
|
const walletJson = JSON.stringify(wallet);
|
|
@@ -3240,45 +3492,54 @@ var ParaCore = class _ParaCore {
|
|
|
3240
3492
|
* Sets the current wallets from a Base 64 string.
|
|
3241
3493
|
* @param {string} base64Wallet the encoded wallet string
|
|
3242
3494
|
**/
|
|
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()
|
|
3495
|
+
setUserShare(base64Wallets) {
|
|
3496
|
+
return __async(this, null, function* () {
|
|
3497
|
+
if (!base64Wallets) {
|
|
3498
|
+
return;
|
|
3499
|
+
}
|
|
3500
|
+
const base64WalletsSplit = base64Wallets.split("-");
|
|
3501
|
+
for (const base64Wallet of base64WalletsSplit) {
|
|
3502
|
+
const walletJson = Buffer.from(base64Wallet, "base64").toString();
|
|
3503
|
+
const wallet = migrateWallet(JSON.parse(walletJson));
|
|
3504
|
+
this.wallets[wallet.id] = wallet;
|
|
3505
|
+
yield this.setWallets(this.wallets);
|
|
3263
3506
|
}
|
|
3264
3507
|
});
|
|
3265
3508
|
}
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3509
|
+
getTransactionReviewUrl(transactionId, timeoutMs) {
|
|
3510
|
+
return __async(this, null, function* () {
|
|
3511
|
+
const res = yield this.touchSession();
|
|
3512
|
+
return this.constructPortalUrl("txReview", {
|
|
3513
|
+
partnerId: res.data.partnerId,
|
|
3514
|
+
pathId: transactionId,
|
|
3515
|
+
params: {
|
|
3516
|
+
email: this.email,
|
|
3517
|
+
timeoutMs: timeoutMs == null ? void 0 : timeoutMs.toString()
|
|
3518
|
+
}
|
|
3519
|
+
});
|
|
3520
|
+
});
|
|
3521
|
+
}
|
|
3522
|
+
getOnRampTransactionUrl(_i) {
|
|
3523
|
+
return __async(this, null, function* () {
|
|
3524
|
+
var _j = _i, {
|
|
3525
|
+
purchaseId,
|
|
3526
|
+
providerKey
|
|
3527
|
+
} = _j, walletParams = __objRest(_j, [
|
|
3528
|
+
"purchaseId",
|
|
3529
|
+
"providerKey"
|
|
3530
|
+
]);
|
|
3531
|
+
const res = yield this.touchSession();
|
|
3532
|
+
const [key, identifier] = (0, import_user_management_client5.extractWalletRef)(walletParams);
|
|
3533
|
+
return this.constructPortalUrl("onRamp", {
|
|
3534
|
+
partnerId: res.data.partnerId,
|
|
3535
|
+
pathId: purchaseId,
|
|
3536
|
+
sessionId: res.data.sessionId,
|
|
3537
|
+
params: {
|
|
3538
|
+
[key]: identifier,
|
|
3539
|
+
providerKey,
|
|
3540
|
+
currentWalletIds: JSON.stringify(this.currentWalletIds)
|
|
3541
|
+
}
|
|
3542
|
+
});
|
|
3282
3543
|
});
|
|
3283
3544
|
}
|
|
3284
3545
|
/**
|
|
@@ -3292,91 +3553,95 @@ var ParaCore = class _ParaCore {
|
|
|
3292
3553
|
* @param {number} [opts.timeout] optional timeout in milliseconds. If not present, defaults to 30 seconds.
|
|
3293
3554
|
* @param {string} [opts.cosmosSignDocBase64] the Cosmos `SignDoc` in base64, if applicable
|
|
3294
3555
|
**/
|
|
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;
|
|
3556
|
+
signMessage(_0) {
|
|
3557
|
+
return __async(this, arguments, function* ({
|
|
3558
|
+
walletId,
|
|
3559
|
+
messageBase64,
|
|
3560
|
+
timeoutMs = 3e4,
|
|
3561
|
+
cosmosSignDocBase64
|
|
3562
|
+
}) {
|
|
3563
|
+
this.assertIsValidWalletId(walletId);
|
|
3564
|
+
const wallet = this.wallets[walletId];
|
|
3565
|
+
let signerId = this.userId;
|
|
3566
|
+
if (wallet.partnerId && !wallet.userId) {
|
|
3567
|
+
signerId = wallet.partnerId;
|
|
3329
3568
|
}
|
|
3330
|
-
signRes =
|
|
3569
|
+
let signRes = yield this.signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64 });
|
|
3570
|
+
let timeStart = Date.now();
|
|
3331
3571
|
if (signRes.pendingTransactionId) {
|
|
3332
|
-
|
|
3572
|
+
this.platformUtils.openPopup(
|
|
3573
|
+
yield this.getTransactionReviewUrl(signRes.pendingTransactionId, timeoutMs),
|
|
3574
|
+
{ type: cosmosSignDocBase64 ? "SIGN_TRANSACTION_REVIEW" /* SIGN_TRANSACTION_REVIEW */ : "SIGN_MESSAGE_REVIEW" /* SIGN_MESSAGE_REVIEW */ }
|
|
3575
|
+
);
|
|
3333
3576
|
} else {
|
|
3334
|
-
|
|
3577
|
+
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes);
|
|
3578
|
+
return signRes;
|
|
3335
3579
|
}
|
|
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
|
|
3580
|
+
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
3581
|
+
while (true) {
|
|
3582
|
+
if (Date.now() - timeStart > timeoutMs) {
|
|
3583
|
+
break;
|
|
3584
|
+
}
|
|
3585
|
+
try {
|
|
3586
|
+
yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
|
|
3587
|
+
} catch (err) {
|
|
3588
|
+
const error = new TransactionReviewDenied();
|
|
3589
|
+
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes, error.message);
|
|
3590
|
+
throw error;
|
|
3591
|
+
}
|
|
3592
|
+
signRes = yield this.signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64 });
|
|
3593
|
+
if (signRes.pendingTransactionId) {
|
|
3594
|
+
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
3595
|
+
} else {
|
|
3596
|
+
break;
|
|
3597
|
+
}
|
|
3598
|
+
}
|
|
3599
|
+
if (signRes.pendingTransactionId) {
|
|
3600
|
+
const error = new TransactionReviewTimeout(
|
|
3601
|
+
yield this.getTransactionReviewUrl(signRes.pendingTransactionId),
|
|
3602
|
+
signRes.pendingTransactionId
|
|
3376
3603
|
);
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3604
|
+
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes, error.message);
|
|
3605
|
+
throw error;
|
|
3606
|
+
}
|
|
3607
|
+
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes);
|
|
3608
|
+
return signRes;
|
|
3609
|
+
});
|
|
3610
|
+
}
|
|
3611
|
+
signMessageInner(_0) {
|
|
3612
|
+
return __async(this, arguments, function* ({
|
|
3613
|
+
wallet,
|
|
3614
|
+
signerId,
|
|
3615
|
+
messageBase64,
|
|
3616
|
+
cosmosSignDocBase64
|
|
3617
|
+
}) {
|
|
3618
|
+
let signRes;
|
|
3619
|
+
switch (wallet.scheme) {
|
|
3620
|
+
case import_user_management_client5.WalletScheme.ED25519:
|
|
3621
|
+
signRes = yield this.platformUtils.ed25519Sign(
|
|
3622
|
+
this.ctx,
|
|
3623
|
+
signerId,
|
|
3624
|
+
wallet.id,
|
|
3625
|
+
wallet.signer,
|
|
3626
|
+
messageBase64,
|
|
3627
|
+
this.retrieveSessionCookie()
|
|
3628
|
+
);
|
|
3629
|
+
break;
|
|
3630
|
+
default:
|
|
3631
|
+
signRes = yield this.platformUtils.signMessage(
|
|
3632
|
+
this.ctx,
|
|
3633
|
+
signerId,
|
|
3634
|
+
wallet.id,
|
|
3635
|
+
wallet.signer,
|
|
3636
|
+
messageBase64,
|
|
3637
|
+
this.retrieveSessionCookie(),
|
|
3638
|
+
wallet.scheme === import_user_management_client5.WalletScheme.DKLS,
|
|
3639
|
+
cosmosSignDocBase64
|
|
3640
|
+
);
|
|
3641
|
+
break;
|
|
3642
|
+
}
|
|
3643
|
+
return signRes;
|
|
3644
|
+
});
|
|
3380
3645
|
}
|
|
3381
3646
|
/**
|
|
3382
3647
|
* Signs a transaction.
|
|
@@ -3386,51 +3651,20 @@ var ParaCore = class _ParaCore {
|
|
|
3386
3651
|
* @param {string} [opts.chainId] the EVM chain id of the chain the transaction is being sent on, if applicable
|
|
3387
3652
|
* @param {number} [opts.timeoutMs] the amount of time to wait for the user to sign the transaction, in milliseconds
|
|
3388
3653
|
**/
|
|
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,
|
|
3654
|
+
signTransaction(_0) {
|
|
3655
|
+
return __async(this, arguments, function* ({
|
|
3404
3656
|
walletId,
|
|
3405
|
-
this.wallets[walletId].signer,
|
|
3406
3657
|
rlpEncodedTxBase64,
|
|
3407
3658
|
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;
|
|
3659
|
+
timeoutMs = 3e4
|
|
3660
|
+
}) {
|
|
3661
|
+
this.assertIsValidWalletId(walletId);
|
|
3662
|
+
const wallet = this.wallets[walletId];
|
|
3663
|
+
let signerId = this.userId;
|
|
3664
|
+
if (wallet.partnerId && !wallet.userId) {
|
|
3665
|
+
signerId = wallet.partnerId;
|
|
3432
3666
|
}
|
|
3433
|
-
signRes =
|
|
3667
|
+
let signRes = yield this.platformUtils.signTransaction(
|
|
3434
3668
|
this.ctx,
|
|
3435
3669
|
signerId,
|
|
3436
3670
|
walletId,
|
|
@@ -3440,22 +3674,55 @@ var ParaCore = class _ParaCore {
|
|
|
3440
3674
|
this.retrieveSessionCookie(),
|
|
3441
3675
|
wallet.scheme === import_user_management_client5.WalletScheme.DKLS
|
|
3442
3676
|
);
|
|
3677
|
+
let timeStart = Date.now();
|
|
3443
3678
|
if (signRes.pendingTransactionId) {
|
|
3444
|
-
|
|
3679
|
+
this.platformUtils.openPopup(
|
|
3680
|
+
yield this.getTransactionReviewUrl(signRes.pendingTransactionId, timeoutMs),
|
|
3681
|
+
{ type: "SIGN_TRANSACTION_REVIEW" /* SIGN_TRANSACTION_REVIEW */ }
|
|
3682
|
+
);
|
|
3445
3683
|
} else {
|
|
3446
|
-
|
|
3684
|
+
dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes);
|
|
3685
|
+
return signRes;
|
|
3447
3686
|
}
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3687
|
+
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
3688
|
+
while (true) {
|
|
3689
|
+
if (Date.now() - timeStart > timeoutMs) {
|
|
3690
|
+
break;
|
|
3691
|
+
}
|
|
3692
|
+
try {
|
|
3693
|
+
yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
|
|
3694
|
+
} catch (err) {
|
|
3695
|
+
const error = new TransactionReviewDenied();
|
|
3696
|
+
dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes, error.message);
|
|
3697
|
+
throw error;
|
|
3698
|
+
}
|
|
3699
|
+
signRes = yield this.platformUtils.signTransaction(
|
|
3700
|
+
this.ctx,
|
|
3701
|
+
signerId,
|
|
3702
|
+
walletId,
|
|
3703
|
+
this.wallets[walletId].signer,
|
|
3704
|
+
rlpEncodedTxBase64,
|
|
3705
|
+
chainId,
|
|
3706
|
+
this.retrieveSessionCookie(),
|
|
3707
|
+
wallet.scheme === import_user_management_client5.WalletScheme.DKLS
|
|
3708
|
+
);
|
|
3709
|
+
if (signRes.pendingTransactionId) {
|
|
3710
|
+
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
3711
|
+
} else {
|
|
3712
|
+
break;
|
|
3713
|
+
}
|
|
3714
|
+
}
|
|
3715
|
+
if (signRes.pendingTransactionId) {
|
|
3716
|
+
const error = new TransactionReviewTimeout(
|
|
3717
|
+
yield this.getTransactionReviewUrl(signRes.pendingTransactionId),
|
|
3718
|
+
signRes.pendingTransactionId
|
|
3719
|
+
);
|
|
3720
|
+
dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes, error.message);
|
|
3721
|
+
throw error;
|
|
3722
|
+
}
|
|
3723
|
+
dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes);
|
|
3724
|
+
return signRes;
|
|
3725
|
+
});
|
|
3459
3726
|
}
|
|
3460
3727
|
/**
|
|
3461
3728
|
* @deprecated
|
|
@@ -3464,34 +3731,36 @@ var ParaCore = class _ParaCore {
|
|
|
3464
3731
|
* @param rlpEncodedTxBase64 - rlp encoded tx as base64 string
|
|
3465
3732
|
* @param chainId - chain id of the chain the transaction is being sent on.
|
|
3466
3733
|
**/
|
|
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,
|
|
3734
|
+
sendTransaction(_0) {
|
|
3735
|
+
return __async(this, arguments, function* ({
|
|
3477
3736
|
walletId,
|
|
3478
|
-
this.wallets[walletId].signer,
|
|
3479
3737
|
rlpEncodedTxBase64,
|
|
3480
|
-
chainId
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3738
|
+
chainId
|
|
3739
|
+
}) {
|
|
3740
|
+
this.assertIsValidWalletId(walletId);
|
|
3741
|
+
const wallet = this.wallets[walletId];
|
|
3742
|
+
const signRes = yield this.platformUtils.sendTransaction(
|
|
3743
|
+
this.ctx,
|
|
3744
|
+
this.userId,
|
|
3745
|
+
walletId,
|
|
3746
|
+
this.wallets[walletId].signer,
|
|
3747
|
+
rlpEncodedTxBase64,
|
|
3748
|
+
chainId,
|
|
3749
|
+
this.retrieveSessionCookie(),
|
|
3750
|
+
wallet.scheme === import_user_management_client5.WalletScheme.DKLS
|
|
3491
3751
|
);
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3752
|
+
if (signRes.pendingTransactionId) {
|
|
3753
|
+
this.platformUtils.openPopup(
|
|
3754
|
+
yield this.getTransactionReviewUrl(signRes.pendingTransactionId),
|
|
3755
|
+
{ type: "SIGN_TRANSACTION_REVIEW" /* SIGN_TRANSACTION_REVIEW */ }
|
|
3756
|
+
);
|
|
3757
|
+
const error = new TransactionReviewError(
|
|
3758
|
+
yield this.getTransactionReviewUrl(signRes.pendingTransactionId)
|
|
3759
|
+
);
|
|
3760
|
+
throw error;
|
|
3761
|
+
}
|
|
3762
|
+
return signRes;
|
|
3763
|
+
});
|
|
3495
3764
|
}
|
|
3496
3765
|
isProviderModalDisabled() {
|
|
3497
3766
|
return !!this.disableProviderModal;
|
|
@@ -3504,36 +3773,38 @@ var ParaCore = class _ParaCore {
|
|
|
3504
3773
|
* @param {string} opts.walletId the wallet ID to use for the transaction, where funds will be sent or withdrawn.
|
|
3505
3774
|
* @param {string} opts.externalWalletAddress the external wallet address to send funds to or withdraw funds from, if using an external wallet.
|
|
3506
3775
|
**/
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3776
|
+
initiateOnRampTransaction(options) {
|
|
3777
|
+
return __async(this, null, function* () {
|
|
3778
|
+
var _b;
|
|
3779
|
+
const _a = options, { params, shouldOpenPopup } = _a, walletParams = __objRest(_a, ["params", "shouldOpenPopup"]);
|
|
3780
|
+
const onRampPurchase = yield this.ctx.client.createOnRampPurchase(__spreadValues({
|
|
3781
|
+
userId: this.userId,
|
|
3782
|
+
params: __spreadProps(__spreadValues({}, params), {
|
|
3783
|
+
address: (_b = walletParams.externalWalletAddress) != null ? _b : this.getDisplayAddress(walletParams.walletId, { addressType: params.walletType })
|
|
3784
|
+
})
|
|
3785
|
+
}, walletParams));
|
|
3786
|
+
const portalUrl = yield this.getOnRampTransactionUrl(__spreadValues({
|
|
3787
|
+
purchaseId: onRampPurchase.id,
|
|
3788
|
+
providerKey: onRampPurchase.providerKey
|
|
3789
|
+
}, walletParams));
|
|
3790
|
+
if (shouldOpenPopup) {
|
|
3791
|
+
this.platformUtils.openPopup(portalUrl, { type: "ON_RAMP_TRANSACTION" /* ON_RAMP_TRANSACTION */ });
|
|
3792
|
+
}
|
|
3793
|
+
return { onRampPurchase, portalUrl };
|
|
3521
3794
|
});
|
|
3522
|
-
if (shouldOpenPopup) {
|
|
3523
|
-
this.platformUtils.openPopup(portalUrl, { type: "ON_RAMP_TRANSACTION" /* ON_RAMP_TRANSACTION */ });
|
|
3524
|
-
}
|
|
3525
|
-
return { onRampPurchase, portalUrl };
|
|
3526
3795
|
}
|
|
3527
3796
|
/**
|
|
3528
3797
|
* Returns `true` if session was successfully kept alive, `false` otherwise.
|
|
3529
3798
|
**/
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3799
|
+
keepSessionAlive() {
|
|
3800
|
+
return __async(this, null, function* () {
|
|
3801
|
+
try {
|
|
3802
|
+
yield this.ctx.client.keepSessionAlive(this.userId);
|
|
3803
|
+
return true;
|
|
3804
|
+
} catch (err) {
|
|
3805
|
+
return false;
|
|
3806
|
+
}
|
|
3807
|
+
});
|
|
3537
3808
|
}
|
|
3538
3809
|
/**
|
|
3539
3810
|
* Serialize the current session for import by another Para instance.
|
|
@@ -3558,34 +3829,37 @@ var ParaCore = class _ParaCore {
|
|
|
3558
3829
|
* Imports a session serialized by another Para instance.
|
|
3559
3830
|
* @param {string} serializedInstanceBase64 the serialized session
|
|
3560
3831
|
*/
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3832
|
+
importSession(serializedInstanceBase64) {
|
|
3833
|
+
return __async(this, null, function* () {
|
|
3834
|
+
var _a;
|
|
3835
|
+
const serializedInstance = Buffer.from(serializedInstanceBase64, "base64").toString("utf8");
|
|
3836
|
+
const sessionInfo = JSON.parse(serializedInstance);
|
|
3837
|
+
yield this.setEmail(sessionInfo.email);
|
|
3838
|
+
yield this.setTelegramUserId(sessionInfo.telegramUserId);
|
|
3839
|
+
yield this.setFarcasterUsername(sessionInfo.farcasterUsername);
|
|
3840
|
+
yield this.setUserId(sessionInfo.userId);
|
|
3841
|
+
yield this.setWallets(sessionInfo.wallets);
|
|
3842
|
+
yield this.setExternalWallets(sessionInfo.externalWallets || {});
|
|
3843
|
+
for (const walletId of Object.keys(this.wallets)) {
|
|
3844
|
+
if (!this.wallets[walletId].userId) {
|
|
3845
|
+
this.wallets[walletId].userId = this.userId;
|
|
3846
|
+
}
|
|
3573
3847
|
}
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3848
|
+
if (Object.keys(sessionInfo.currentWalletIds).length !== 0) {
|
|
3849
|
+
yield this.setCurrentWalletIds(sessionInfo.currentWalletIds);
|
|
3850
|
+
} else {
|
|
3851
|
+
const currentWalletIds = {};
|
|
3852
|
+
for (const walletId of Object.keys(sessionInfo.wallets)) {
|
|
3853
|
+
currentWalletIds[sessionInfo.wallets[walletId].type] = [
|
|
3854
|
+
...(_a = currentWalletIds[sessionInfo.wallets[walletId].type]) != null ? _a : [],
|
|
3855
|
+
walletId
|
|
3856
|
+
];
|
|
3857
|
+
}
|
|
3858
|
+
yield this.setCurrentWalletIds(currentWalletIds);
|
|
3584
3859
|
}
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
await this.setPhoneNumber(sessionInfo.phone, sessionInfo.countryCode);
|
|
3860
|
+
this.persistSessionCookie(sessionInfo.sessionCookie);
|
|
3861
|
+
yield this.setPhoneNumber(sessionInfo.phone, sessionInfo.countryCode);
|
|
3862
|
+
});
|
|
3589
3863
|
}
|
|
3590
3864
|
exitAccountCreation() {
|
|
3591
3865
|
this.isAwaitingAccountCreation = false;
|
|
@@ -3609,48 +3883,54 @@ var ParaCore = class _ParaCore {
|
|
|
3609
3883
|
* Retrieves a token to verify the current session.
|
|
3610
3884
|
* @returns {Promise<string>} the ID
|
|
3611
3885
|
**/
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3886
|
+
getVerificationToken() {
|
|
3887
|
+
return __async(this, null, function* () {
|
|
3888
|
+
const { data } = yield this.touchSession();
|
|
3889
|
+
return data.sessionLookupId;
|
|
3890
|
+
});
|
|
3615
3891
|
}
|
|
3616
3892
|
/**
|
|
3617
3893
|
* Logs the user out.
|
|
3618
3894
|
* @param {Object} opts the options object.
|
|
3619
3895
|
* @param {boolean} opts.clearPregenWallets if `true`, will remove all pregen wallets from storage
|
|
3620
3896
|
**/
|
|
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
|
-
|
|
3897
|
+
logout() {
|
|
3898
|
+
return __async(this, arguments, function* ({ clearPregenWallets = false } = {}) {
|
|
3899
|
+
yield this.ctx.client.logout();
|
|
3900
|
+
yield this.clearStorage();
|
|
3901
|
+
if (!clearPregenWallets) {
|
|
3902
|
+
Object.entries(this.wallets).forEach(([id, wallet]) => {
|
|
3903
|
+
if (!wallet.pregenIdentifier) {
|
|
3904
|
+
delete this.wallets[id];
|
|
3905
|
+
}
|
|
3906
|
+
});
|
|
3907
|
+
yield this.setWallets(this.wallets);
|
|
3908
|
+
} else {
|
|
3909
|
+
this.wallets = {};
|
|
3910
|
+
}
|
|
3911
|
+
this.currentWalletIds = {};
|
|
3912
|
+
this.externalWallets = {};
|
|
3913
|
+
this.loginEncryptionKeyPair = void 0;
|
|
3914
|
+
this.email = void 0;
|
|
3915
|
+
this.telegramUserId = void 0;
|
|
3916
|
+
this.phone = void 0;
|
|
3917
|
+
this.countryCode = void 0;
|
|
3918
|
+
this.userId = void 0;
|
|
3919
|
+
this.sessionCookie = void 0;
|
|
3920
|
+
dispatchEvent(ParaEvent.LOGOUT_EVENT, null);
|
|
3921
|
+
});
|
|
3922
|
+
}
|
|
3923
|
+
getSupportedCreateAuthMethods() {
|
|
3924
|
+
return __async(this, null, function* () {
|
|
3925
|
+
const res = yield this.touchSession();
|
|
3926
|
+
const partnerId = res.data.partnerId;
|
|
3927
|
+
const partnerRes = yield this.ctx.client.getPartner(partnerId);
|
|
3928
|
+
let supportedAuthMethods = /* @__PURE__ */ new Set();
|
|
3929
|
+
for (const authMethod of partnerRes.data.partner.supportedAuthMethods) {
|
|
3930
|
+
supportedAuthMethods.add(import_user_management_client5.AuthMethod[authMethod]);
|
|
3931
|
+
}
|
|
3932
|
+
return supportedAuthMethods;
|
|
3933
|
+
});
|
|
3654
3934
|
}
|
|
3655
3935
|
/**
|
|
3656
3936
|
* Converts to a string, removing sensitive data when logging this class.
|
|
@@ -3659,12 +3939,10 @@ var ParaCore = class _ParaCore {
|
|
|
3659
3939
|
**/
|
|
3660
3940
|
toString() {
|
|
3661
3941
|
const redactedWallets = Object.keys(this.wallets).reduce(
|
|
3662
|
-
(acc, walletId) => ({
|
|
3663
|
-
|
|
3664
|
-
[walletId]: {
|
|
3665
|
-
...this.wallets[walletId],
|
|
3942
|
+
(acc, walletId) => __spreadProps(__spreadValues({}, acc), {
|
|
3943
|
+
[walletId]: __spreadProps(__spreadValues({}, this.wallets[walletId]), {
|
|
3666
3944
|
signer: this.wallets[walletId].signer ? "[REDACTED]" : void 0
|
|
3667
|
-
}
|
|
3945
|
+
})
|
|
3668
3946
|
}),
|
|
3669
3947
|
{}
|
|
3670
3948
|
);
|
|
@@ -3695,6 +3973,10 @@ var ParaCore = class _ParaCore {
|
|
|
3695
3973
|
return `Para ${JSON.stringify(obj, null, 2)}`;
|
|
3696
3974
|
}
|
|
3697
3975
|
};
|
|
3976
|
+
_supportedWalletTypes = new WeakMap();
|
|
3977
|
+
_supportedWalletTypesOpt = new WeakMap();
|
|
3978
|
+
_ParaCore.version = PARA_CORE_VERSION;
|
|
3979
|
+
var ParaCore = _ParaCore;
|
|
3698
3980
|
|
|
3699
3981
|
// src/index.ts
|
|
3700
3982
|
var import_user_management_client6 = require("@getpara/user-management-client");
|