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