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