@getpara/core-sdk 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/.!4420!index.js.br +0 -0
- package/dist/cjs/.!4422!index.js.gz +0 -0
- package/dist/cjs/index.js +2 -97
- package/dist/cjs/index.js.br +0 -0
- package/dist/cjs/index.js.gz +0 -0
- package/dist/esm/.!4417!index.js.br +0 -0
- package/dist/esm/.!4419!index.js.gz +0 -0
- package/dist/esm/index.js +2 -23
- package/dist/esm/index.js.br +0 -0
- package/dist/esm/index.js.gz +0 -0
- package/dist/types/ParaCore.d.ts +8 -1
- package/package.json +7 -7
- package/dist/cjs/ParaCore.js +0 -2606
- package/dist/cjs/PlatformUtils.js +0 -2
- package/dist/cjs/StorageUtils.js +0 -2
- package/dist/cjs/constants.js +0 -20
- package/dist/cjs/cryptography/utils.js +0 -251
- package/dist/cjs/errors.js +0 -27
- package/dist/cjs/external/mpcComputationClient.js +0 -33
- package/dist/cjs/external/userManagementClient.js +0 -66
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/shares/KeyContainer.js +0 -84
- package/dist/cjs/shares/recovery.js +0 -62
- package/dist/cjs/shares/shareDistribution.js +0 -67
- package/dist/cjs/transmission/transmissionUtils.js +0 -73
- package/dist/cjs/types/config.js +0 -22
- package/dist/cjs/types/events.js +0 -17
- package/dist/cjs/types/index.js +0 -30
- package/dist/cjs/types/onRamps.js +0 -10
- package/dist/cjs/types/params.js +0 -2
- package/dist/cjs/types/popup.js +0 -12
- package/dist/cjs/types/recovery.js +0 -12
- package/dist/cjs/types/theme.js +0 -2
- package/dist/cjs/types/wallet.js +0 -9
- package/dist/cjs/utils/events.js +0 -9
- package/dist/cjs/utils/formatting.js +0 -81
- package/dist/cjs/utils/index.js +0 -22
- package/dist/cjs/utils/onRamps.js +0 -36
- package/dist/cjs/utils/polling.js +0 -25
- package/dist/cjs/utils/url.js +0 -74
- package/dist/cjs/utils/wallet.js +0 -74
- package/dist/esm/ParaCore.js +0 -2576
- package/dist/esm/PlatformUtils.js +0 -1
- package/dist/esm/StorageUtils.js +0 -1
- package/dist/esm/constants.js +0 -17
- package/dist/esm/cryptography/utils.js +0 -226
- package/dist/esm/errors.js +0 -21
- package/dist/esm/external/mpcComputationClient.js +0 -26
- package/dist/esm/external/userManagementClient.js +0 -56
- package/dist/esm/package.json +0 -1
- package/dist/esm/shares/KeyContainer.js +0 -57
- package/dist/esm/shares/recovery.js +0 -58
- package/dist/esm/shares/shareDistribution.js +0 -63
- package/dist/esm/transmission/transmissionUtils.js +0 -45
- package/dist/esm/types/config.js +0 -19
- package/dist/esm/types/events.js +0 -14
- package/dist/esm/types/index.js +0 -9
- package/dist/esm/types/onRamps.js +0 -7
- package/dist/esm/types/params.js +0 -1
- package/dist/esm/types/popup.js +0 -9
- package/dist/esm/types/recovery.js +0 -9
- package/dist/esm/types/theme.js +0 -1
- package/dist/esm/types/wallet.js +0 -6
- package/dist/esm/utils/events.js +0 -5
- package/dist/esm/utils/formatting.js +0 -66
- package/dist/esm/utils/index.js +0 -6
- package/dist/esm/utils/onRamps.js +0 -30
- package/dist/esm/utils/polling.js +0 -21
- package/dist/esm/utils/url.js +0 -66
- package/dist/esm/utils/wallet.js +0 -64
package/dist/cjs/ParaCore.js
DELETED
|
@@ -1,2606 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
35
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
36
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
37
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
38
|
-
};
|
|
39
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
40
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
41
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
42
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
43
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
44
|
-
};
|
|
45
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
46
|
-
var t = {};
|
|
47
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
48
|
-
t[p] = s[p];
|
|
49
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
50
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
51
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
52
|
-
t[p[i]] = s[p[i]];
|
|
53
|
-
}
|
|
54
|
-
return t;
|
|
55
|
-
};
|
|
56
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
57
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
58
|
-
};
|
|
59
|
-
var _ParaCore_supportedWalletTypes, _ParaCore_supportedWalletTypesOpt;
|
|
60
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
61
|
-
exports.ParaCore = void 0;
|
|
62
|
-
const buffer_1 = require("buffer");
|
|
63
|
-
if (typeof global !== 'undefined') {
|
|
64
|
-
global.Buffer = global.Buffer || buffer_1.Buffer;
|
|
65
|
-
}
|
|
66
|
-
else if (typeof window !== 'undefined') {
|
|
67
|
-
window.Buffer = window.Buffer || buffer_1.Buffer;
|
|
68
|
-
window.global = window.global || window;
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
self.Buffer = self.Buffer || buffer_1.Buffer;
|
|
72
|
-
self.global = self.global || self;
|
|
73
|
-
}
|
|
74
|
-
const user_management_client_1 = require("@getpara/user-management-client");
|
|
75
|
-
const node_forge_1 = __importDefault(require("node-forge"));
|
|
76
|
-
const { pki, jsbn } = node_forge_1.default;
|
|
77
|
-
const utils_js_1 = require("./cryptography/utils.js");
|
|
78
|
-
const userManagementClient_js_1 = require("./external/userManagementClient.js");
|
|
79
|
-
const mpcComputationClient = __importStar(require("./external/mpcComputationClient.js"));
|
|
80
|
-
const shareDistribution_js_1 = require("./shares/shareDistribution.js");
|
|
81
|
-
const index_js_1 = require("./types/index.js");
|
|
82
|
-
const transmissionUtils = __importStar(require("./transmission/transmissionUtils.js"));
|
|
83
|
-
const recovery_js_1 = require("./shares/recovery.js");
|
|
84
|
-
const index_js_2 = require("./utils/index.js");
|
|
85
|
-
const errors_js_1 = require("./errors.js");
|
|
86
|
-
const constants = __importStar(require("./constants.js"));
|
|
87
|
-
class ParaCore {
|
|
88
|
-
get isEmail() {
|
|
89
|
-
return !!this.email && !this.phone && !this.countryCode && !this.farcasterUsername && !this.telegramUserId;
|
|
90
|
-
}
|
|
91
|
-
get isPhone() {
|
|
92
|
-
return !!this.phone && !!this.countryCode && !this.email && !this.farcasterUsername && !this.telegramUserId;
|
|
93
|
-
}
|
|
94
|
-
get isFarcaster() {
|
|
95
|
-
return !!this.farcasterUsername && !this.email && !this.phone && !this.countryCode && !this.telegramUserId;
|
|
96
|
-
}
|
|
97
|
-
get isTelegram() {
|
|
98
|
-
return !!this.telegramUserId && !this.email && !this.phone && !this.countryCode && !this.farcasterUsername;
|
|
99
|
-
}
|
|
100
|
-
get currentWalletIdsArray() {
|
|
101
|
-
return this.supportedWalletTypes.reduce((acc, { type }) => {
|
|
102
|
-
var _a;
|
|
103
|
-
return [
|
|
104
|
-
...acc,
|
|
105
|
-
...((_a = this.currentWalletIds[type]) !== null && _a !== void 0 ? _a : []).map(id => {
|
|
106
|
-
return [id, type];
|
|
107
|
-
}),
|
|
108
|
-
];
|
|
109
|
-
}, []);
|
|
110
|
-
}
|
|
111
|
-
get currentWalletIdsUnique() {
|
|
112
|
-
return [...new Set(Object.values(this.currentWalletIds).flat())];
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* A map of pre-generated wallet identifiers that can be claimed in the current instance.
|
|
116
|
-
*/
|
|
117
|
-
get pregenIds() {
|
|
118
|
-
return Object.assign({}, Object.values(this.wallets)
|
|
119
|
-
.filter(wallet => !this.userId || this.isPregenWalletClaimable(wallet))
|
|
120
|
-
.reduce((acc, wallet) => {
|
|
121
|
-
var _a, _b;
|
|
122
|
-
if (((_a = acc[wallet.pregenIdentifierType]) !== null && _a !== void 0 ? _a : []).includes(wallet.pregenIdentifier)) {
|
|
123
|
-
return acc;
|
|
124
|
-
}
|
|
125
|
-
return Object.assign(Object.assign({}, acc), { [wallet.pregenIdentifierType]: [
|
|
126
|
-
...new Set([...((_b = acc[wallet.pregenIdentifierType]) !== null && _b !== void 0 ? _b : []), wallet.pregenIdentifier]),
|
|
127
|
-
] });
|
|
128
|
-
}, {}));
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Whether the instance has multiple wallets connected.
|
|
132
|
-
*/
|
|
133
|
-
get isMultiWallet() {
|
|
134
|
-
return this.currentWalletIdsArray.length > 1;
|
|
135
|
-
}
|
|
136
|
-
get supportedWalletTypes() {
|
|
137
|
-
var _a;
|
|
138
|
-
return (_a = __classPrivateFieldGet(this, _ParaCore_supportedWalletTypes, "f")) !== null && _a !== void 0 ? _a : [];
|
|
139
|
-
}
|
|
140
|
-
get isWalletTypeEnabled() {
|
|
141
|
-
return this.supportedWalletTypes.reduce((acc, { type }) => {
|
|
142
|
-
return Object.assign(Object.assign({}, acc), { [type]: true });
|
|
143
|
-
}, {});
|
|
144
|
-
}
|
|
145
|
-
convertBigInt(bigInt) {
|
|
146
|
-
const convertedBigInt = new jsbn.BigInteger(null);
|
|
147
|
-
convertedBigInt.data = bigInt.data;
|
|
148
|
-
convertedBigInt.s = bigInt.s;
|
|
149
|
-
convertedBigInt.t = bigInt.t;
|
|
150
|
-
return convertedBigInt;
|
|
151
|
-
}
|
|
152
|
-
convertEncryptionKeyPair(jsonKeyPair) {
|
|
153
|
-
return {
|
|
154
|
-
privateKey: pki.setRsaPrivateKey(this.convertBigInt(jsonKeyPair.privateKey.n), this.convertBigInt(jsonKeyPair.privateKey.e), this.convertBigInt(jsonKeyPair.privateKey.d), this.convertBigInt(jsonKeyPair.privateKey.p), this.convertBigInt(jsonKeyPair.privateKey.q), this.convertBigInt(jsonKeyPair.privateKey.dP), this.convertBigInt(jsonKeyPair.privateKey.dQ), this.convertBigInt(jsonKeyPair.privateKey.qInv)),
|
|
155
|
-
publicKey: pki.setRsaPublicKey(this.convertBigInt(jsonKeyPair.publicKey.n), this.convertBigInt(jsonKeyPair.publicKey.e)),
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
isPortal(envOverride) {
|
|
159
|
-
var _a;
|
|
160
|
-
if (typeof window === 'undefined')
|
|
161
|
-
return false;
|
|
162
|
-
return (!!((_a = window.location) === null || _a === void 0 ? void 0 : _a.host) &&
|
|
163
|
-
(0, index_js_2.getPortalBaseURL)(envOverride ? { env: envOverride } : this.ctx).includes(window.location.host));
|
|
164
|
-
}
|
|
165
|
-
isParaConnect() {
|
|
166
|
-
var _a;
|
|
167
|
-
if (typeof window === 'undefined')
|
|
168
|
-
return false;
|
|
169
|
-
return !!((_a = window.location) === null || _a === void 0 ? void 0 : _a.host) && (0, index_js_2.getParaConnectBaseUrl)(this.ctx).includes(window.location.host);
|
|
170
|
-
}
|
|
171
|
-
requireApiKey() {
|
|
172
|
-
if (!this.ctx.apiKey) {
|
|
173
|
-
throw new Error(`in order to create a wallet or user with Para, you
|
|
174
|
-
must provide an API key to the Para instance`);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
isWalletSupported(wallet) {
|
|
178
|
-
var _a;
|
|
179
|
-
return !__classPrivateFieldGet(this, _ParaCore_supportedWalletTypes, "f") || (0, index_js_2.isWalletSupported)((_a = this.supportedWalletTypes.map(({ type }) => type)) !== null && _a !== void 0 ? _a : [], wallet);
|
|
180
|
-
}
|
|
181
|
-
isWalletOwned(wallet) {
|
|
182
|
-
return (this.isWalletSupported(wallet) &&
|
|
183
|
-
!wallet.pregenIdentifier &&
|
|
184
|
-
!wallet.pregenIdentifierType &&
|
|
185
|
-
!!this.userId &&
|
|
186
|
-
wallet.userId === this.userId);
|
|
187
|
-
}
|
|
188
|
-
isPregenWalletUnclaimed(wallet) {
|
|
189
|
-
return (this.isWalletSupported(wallet) &&
|
|
190
|
-
(!wallet.userId || (wallet.isPregen && !!wallet.pregenIdentifier && !!wallet.pregenIdentifierType)));
|
|
191
|
-
}
|
|
192
|
-
isPregenWalletClaimable(wallet) {
|
|
193
|
-
return (this.isWalletSupported(wallet) &&
|
|
194
|
-
this.isPregenWalletUnclaimed(wallet) &&
|
|
195
|
-
(!['EMAIL', 'PHONE', 'TELEGRAM'].includes(wallet.pregenIdentifierType) ||
|
|
196
|
-
(0, index_js_2.isPregenIdentifierMatch)(wallet.pregenIdentifierType === 'EMAIL'
|
|
197
|
-
? this.email
|
|
198
|
-
: wallet.pregenIdentifierType === 'TELEGRAM'
|
|
199
|
-
? this.telegramUserId
|
|
200
|
-
: this.getPhoneNumber(), wallet.pregenIdentifier, wallet.pregenIdentifierType)));
|
|
201
|
-
}
|
|
202
|
-
isWalletUsable(walletId, { type: types, scheme: schemes, forbidPregen = false } = {}, throwError = false) {
|
|
203
|
-
let error;
|
|
204
|
-
if (!this.wallets[walletId]) {
|
|
205
|
-
error = `wallet with id ${walletId} does not exist`;
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
const wallet = this.wallets[walletId];
|
|
209
|
-
const [isUnclaimed, isOwned] = [this.isPregenWalletUnclaimed(wallet), this.isWalletOwned(wallet)];
|
|
210
|
-
if (forbidPregen && isUnclaimed) {
|
|
211
|
-
error = `pre-generated wallet with id ${wallet.id} cannot be selected`;
|
|
212
|
-
}
|
|
213
|
-
else if (!isOwned && !isUnclaimed) {
|
|
214
|
-
error = `wallet with id ${wallet.id} is not owned by the current user`;
|
|
215
|
-
}
|
|
216
|
-
else if (!this.isWalletSupported(wallet)) {
|
|
217
|
-
error = `wallet with id ${wallet.id} and type ${wallet.type} is not supported, supported types are: ${this.supportedWalletTypes.map(({ type }) => type).join(', ')}`;
|
|
218
|
-
}
|
|
219
|
-
else if (types &&
|
|
220
|
-
(!(0, index_js_2.getEquivalentTypes)(types).includes(wallet.type) ||
|
|
221
|
-
(isOwned && !types.some(type => { var _a; return ((_a = this.currentWalletIds[type]) !== null && _a !== void 0 ? _a : []).includes(walletId); })))) {
|
|
222
|
-
error = `wallet with id ${wallet.id} and type ${wallet.type} cannot be selected`;
|
|
223
|
-
}
|
|
224
|
-
else if (schemes && !schemes.includes(wallet.scheme)) {
|
|
225
|
-
error = `wallet with id ${wallet.id} and scheme ${wallet.scheme} cannot be selected`;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
if (error) {
|
|
229
|
-
if (throwError) {
|
|
230
|
-
throw new Error(error);
|
|
231
|
-
}
|
|
232
|
-
return false;
|
|
233
|
-
}
|
|
234
|
-
return true;
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Returns the formatted address for the desired wallet ID, depending on your app settings.
|
|
238
|
-
* @param {string} walletId the ID of the wallet address to display.
|
|
239
|
-
* @param {object} options additional options for formatting the address.
|
|
240
|
-
* @param {boolean} options.truncate whether to truncate the address.
|
|
241
|
-
* @param {WalletType} options.addressType the type of address to display.
|
|
242
|
-
* @returns the formatted address
|
|
243
|
-
*/
|
|
244
|
-
getDisplayAddress(walletId, options = {}) {
|
|
245
|
-
var _a;
|
|
246
|
-
if (this.externalWallets[walletId]) {
|
|
247
|
-
const wallet = this.externalWallets[walletId];
|
|
248
|
-
return options.truncate ? (0, index_js_2.truncateAddress)(wallet.address, wallet.type, { prefix: this.cosmosPrefix }) : wallet.address;
|
|
249
|
-
}
|
|
250
|
-
const wallet = this.findWallet(walletId, options.addressType);
|
|
251
|
-
if (!wallet) {
|
|
252
|
-
return undefined;
|
|
253
|
-
}
|
|
254
|
-
let str;
|
|
255
|
-
switch (wallet.type) {
|
|
256
|
-
case user_management_client_1.WalletType.COSMOS:
|
|
257
|
-
str = (0, index_js_2.getCosmosAddress)(wallet.publicKey, (_a = this.cosmosPrefix) !== null && _a !== void 0 ? _a : 'cosmos');
|
|
258
|
-
break;
|
|
259
|
-
default:
|
|
260
|
-
str = wallet.address;
|
|
261
|
-
break;
|
|
262
|
-
}
|
|
263
|
-
return options.truncate ? (0, index_js_2.truncateAddress)(str, wallet.type, { prefix: this.cosmosPrefix }) : str;
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* Returns a unique hash for a wallet suitable for use as an identicon seed.
|
|
267
|
-
* @param {string} walletId the ID of the wallet.
|
|
268
|
-
* @param {boolean} options.addressType used to format the hash for another wallet type.
|
|
269
|
-
* @returns the identicon hash string
|
|
270
|
-
*/
|
|
271
|
-
getIdenticonHash(walletId, overrideType) {
|
|
272
|
-
if (this.externalWallets[walletId]) {
|
|
273
|
-
const wallet = this.externalWallets[walletId];
|
|
274
|
-
return `${wallet.id}-${wallet.address}-${wallet.type}`;
|
|
275
|
-
}
|
|
276
|
-
const wallet = this.findWallet(walletId, overrideType);
|
|
277
|
-
return wallet ? `${wallet.id}-${wallet.address}-${wallet.type}` : undefined;
|
|
278
|
-
}
|
|
279
|
-
getWallets() {
|
|
280
|
-
return this.wallets;
|
|
281
|
-
}
|
|
282
|
-
getAddress(walletId) {
|
|
283
|
-
var _a, _b;
|
|
284
|
-
return walletId ? this.wallets[walletId].address : (_b = (_a = Object.values(this.wallets)) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.address;
|
|
285
|
-
}
|
|
286
|
-
constructPortalUrl(type, opts = {}) {
|
|
287
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
288
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
289
|
-
const base = type === 'onRamp' ? (0, index_js_2.getPortalBaseURL)(this.ctx) : yield this.getPortalURL(opts.partnerId);
|
|
290
|
-
let path;
|
|
291
|
-
switch (type) {
|
|
292
|
-
case 'createPassword': {
|
|
293
|
-
path = `/web/users/${this.userId}/passwords/${opts.pathId}`;
|
|
294
|
-
break;
|
|
295
|
-
}
|
|
296
|
-
case 'createAuth': {
|
|
297
|
-
path = `/web/users/${this.userId}/biometrics/${opts.pathId}`;
|
|
298
|
-
break;
|
|
299
|
-
}
|
|
300
|
-
case 'loginPassword': {
|
|
301
|
-
path = '/web/passwords/login';
|
|
302
|
-
break;
|
|
303
|
-
}
|
|
304
|
-
case 'loginAuth': {
|
|
305
|
-
path = '/web/biometrics/login';
|
|
306
|
-
break;
|
|
307
|
-
}
|
|
308
|
-
case 'txReview': {
|
|
309
|
-
path = `/web/users/${this.userId}/transaction-review/${opts.pathId}`;
|
|
310
|
-
break;
|
|
311
|
-
}
|
|
312
|
-
case 'onRamp': {
|
|
313
|
-
path = `/web/users/${this.userId}/on-ramp-transaction/${opts.pathId}`;
|
|
314
|
-
break;
|
|
315
|
-
}
|
|
316
|
-
default: {
|
|
317
|
-
throw new Error(`invalid URL type ${type}`);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
const [isCreate, isLogin, isOnRamp] = [
|
|
321
|
-
['createAuth', 'createPassword'].includes(type),
|
|
322
|
-
['loginAuth', 'loginPassword'].includes(type),
|
|
323
|
-
type === 'onRamp',
|
|
324
|
-
];
|
|
325
|
-
const partner = opts.partnerId
|
|
326
|
-
? (_a = (yield this.ctx.client.getPartner(opts.partnerId)).data) === null || _a === void 0 ? void 0 : _a.partner
|
|
327
|
-
: undefined;
|
|
328
|
-
const params = Object.assign(Object.assign(Object.assign(Object.assign({ apiKey: this.ctx.apiKey, partnerId: opts.partnerId, portalFont: ((_b = opts.theme) === null || _b === void 0 ? void 0 : _b.font) || (partner === null || partner === void 0 ? void 0 : partner.font) || ((_c = this.portalTheme) === null || _c === void 0 ? void 0 : _c.font), portalBorderRadius: ((_d = opts.theme) === null || _d === void 0 ? void 0 : _d.borderRadius) || ((_e = this.portalTheme) === null || _e === void 0 ? void 0 : _e.borderRadius), portalThemeMode: ((_f = opts.theme) === null || _f === void 0 ? void 0 : _f.mode) || (partner === null || partner === void 0 ? void 0 : partner.themeMode) || ((_g = this.portalTheme) === null || _g === void 0 ? void 0 : _g.mode), portalAccentColor: ((_h = opts.theme) === null || _h === void 0 ? void 0 : _h.accentColor) || (partner === null || partner === void 0 ? void 0 : partner.accentColor) || ((_j = this.portalTheme) === null || _j === void 0 ? void 0 : _j.accentColor), portalForegroundColor: ((_k = opts.theme) === null || _k === void 0 ? void 0 : _k.foregroundColor) || (partner === null || partner === void 0 ? void 0 : partner.foregroundColor) || ((_l = this.portalTheme) === null || _l === void 0 ? void 0 : _l.foregroundColor), portalBackgroundColor: ((_m = opts.theme) === null || _m === void 0 ? void 0 : _m.backgroundColor) ||
|
|
329
|
-
(partner === null || partner === void 0 ? void 0 : partner.backgroundColor) ||
|
|
330
|
-
this.portalBackgroundColor ||
|
|
331
|
-
((_o = this.portalTheme) === null || _o === void 0 ? void 0 : _o.backgroundColor), portalPrimaryButtonColor: this.portalPrimaryButtonColor, portalTextColor: this.portalTextColor, portalPrimaryButtonTextColor: this.portalPrimaryButtonTextColor, isForNewDevice: opts.isForNewDevice ? opts.isForNewDevice.toString() : undefined, supportedWalletTypes: __classPrivateFieldGet(this, _ParaCore_supportedWalletTypesOpt, "f") ? JSON.stringify(__classPrivateFieldGet(this, _ParaCore_supportedWalletTypesOpt, "f")) : undefined }, (isCreate || isLogin
|
|
332
|
-
? Object.assign(Object.assign(Object.assign(Object.assign({}, (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
|
|
333
|
-
? {
|
|
334
|
-
encryptionKey: opts.loginEncryptionPublicKey,
|
|
335
|
-
newDeviceSessionLookupId: opts.newDeviceSessionId,
|
|
336
|
-
newDeviceEncryptionKey: opts.newDeviceEncryptionKey,
|
|
337
|
-
pregenIds: JSON.stringify(this.pregenIds),
|
|
338
|
-
displayName: opts.displayName,
|
|
339
|
-
pfpUrl: opts.pfpUrl,
|
|
340
|
-
}
|
|
341
|
-
: {})), (opts.params || {}));
|
|
342
|
-
return (0, index_js_2.constructUrl)({ base, path, params });
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
/**
|
|
346
|
-
* Constructs a new `ParaCore` instance.
|
|
347
|
-
* @param env - `Environment` to use.
|
|
348
|
-
* @param apiKey - API key to use.
|
|
349
|
-
* @param opts - Additional constructor options; see `ConstructorOpts`.
|
|
350
|
-
* @returns - A new ParaCore instance.
|
|
351
|
-
*/
|
|
352
|
-
constructor(env, apiKey, opts) {
|
|
353
|
-
var _a;
|
|
354
|
-
this.isAwaitingAccountCreation = false;
|
|
355
|
-
this.isAwaitingLogin = false;
|
|
356
|
-
this.isAwaitingFarcaster = false;
|
|
357
|
-
this.isAwaitingOAuth = false;
|
|
358
|
-
/**
|
|
359
|
-
* 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.
|
|
360
|
-
*/
|
|
361
|
-
this.currentWalletIds = {};
|
|
362
|
-
_ParaCore_supportedWalletTypes.set(this, undefined);
|
|
363
|
-
_ParaCore_supportedWalletTypesOpt.set(this, undefined);
|
|
364
|
-
this.localStorageGetItem = (key) => {
|
|
365
|
-
return this.platformUtils.localStorage.get(key);
|
|
366
|
-
};
|
|
367
|
-
this.localStorageSetItem = (key, value) => {
|
|
368
|
-
return this.platformUtils.localStorage.set(key, value);
|
|
369
|
-
};
|
|
370
|
-
this.sessionStorageGetItem = (key) => {
|
|
371
|
-
return this.platformUtils.sessionStorage.get(key);
|
|
372
|
-
};
|
|
373
|
-
this.sessionStorageSetItem = (key, value) => {
|
|
374
|
-
return this.platformUtils.sessionStorage.set(key, value);
|
|
375
|
-
};
|
|
376
|
-
this.sessionStorageRemoveItem = (key) => {
|
|
377
|
-
return this.platformUtils.sessionStorage.removeItem(key);
|
|
378
|
-
};
|
|
379
|
-
this.retrieveSessionCookie = () => {
|
|
380
|
-
return this.sessionCookie;
|
|
381
|
-
};
|
|
382
|
-
/**
|
|
383
|
-
* Remove all local storage and prefixed session storage.
|
|
384
|
-
* @param {'local' | 'session' | 'secure' | 'all'} type - Type of storage to clear. Defaults to 'all'.
|
|
385
|
-
*/
|
|
386
|
-
this.clearStorage = (type = 'all') => __awaiter(this, void 0, void 0, function* () {
|
|
387
|
-
const isAll = type === 'all';
|
|
388
|
-
(isAll || type === 'local') && this.platformUtils.localStorage.clear(constants.PREFIX);
|
|
389
|
-
(isAll || type === 'session') && this.platformUtils.sessionStorage.clear(constants.PREFIX);
|
|
390
|
-
if ((isAll || type === 'secure') && this.platformUtils.secureStorage) {
|
|
391
|
-
this.platformUtils.secureStorage.clear(constants.PREFIX);
|
|
392
|
-
}
|
|
393
|
-
});
|
|
394
|
-
/**
|
|
395
|
-
* Creates several new wallets with the desired types. If no types are provided, this method
|
|
396
|
-
* will create one for each of the non-optional types specified in the instance's `supportedWalletTypes`
|
|
397
|
-
* object that are not already present. This is automatically called upon account creation to ensure that
|
|
398
|
-
* the user has a wallet of each required type.
|
|
399
|
-
*
|
|
400
|
-
* @deprecated alias for `createWalletPerType`
|
|
401
|
-
**/
|
|
402
|
-
this.createWalletPerMissingType = this.createWalletPerType;
|
|
403
|
-
// TODO: consider using sessionStorage instead of localStorage
|
|
404
|
-
if (!opts)
|
|
405
|
-
opts = {};
|
|
406
|
-
this.emailPrimaryColor = opts.emailPrimaryColor;
|
|
407
|
-
this.emailTheme = opts.emailTheme;
|
|
408
|
-
this.homepageUrl = opts.homepageUrl;
|
|
409
|
-
this.supportUrl = opts.supportUrl;
|
|
410
|
-
this.xUrl = opts.xUrl;
|
|
411
|
-
this.githubUrl = opts.githubUrl;
|
|
412
|
-
this.linkedinUrl = opts.linkedinUrl;
|
|
413
|
-
this.portalBackgroundColor = opts.portalBackgroundColor;
|
|
414
|
-
this.portalPrimaryButtonColor = opts.portalPrimaryButtonColor;
|
|
415
|
-
this.portalTextColor = opts.portalTextColor;
|
|
416
|
-
this.portalPrimaryButtonTextColor = opts.portalPrimaryButtonTextColor;
|
|
417
|
-
this.portalTheme = opts.portalTheme;
|
|
418
|
-
this.platformUtils = this.getPlatformUtils();
|
|
419
|
-
this.disableProviderModal = this.platformUtils.disableProviderModal;
|
|
420
|
-
if (opts.useStorageOverrides) {
|
|
421
|
-
this.localStorageGetItem = opts.localStorageGetItemOverride;
|
|
422
|
-
this.localStorageSetItem = opts.localStorageSetItemOverride;
|
|
423
|
-
this.sessionStorageGetItem = opts.sessionStorageGetItemOverride;
|
|
424
|
-
this.sessionStorageSetItem = opts.sessionStorageSetItemOverride;
|
|
425
|
-
this.sessionStorageRemoveItem = opts.sessionStorageRemoveItemOverride;
|
|
426
|
-
this.clearStorage = opts.clearStorageOverride;
|
|
427
|
-
}
|
|
428
|
-
if (opts.useSessionStorage) {
|
|
429
|
-
this.localStorageGetItem = this.sessionStorageGetItem;
|
|
430
|
-
this.localStorageSetItem = this.sessionStorageSetItem;
|
|
431
|
-
}
|
|
432
|
-
this.persistSessionCookie = (cookie) => {
|
|
433
|
-
this.sessionCookie = cookie;
|
|
434
|
-
(opts.useSessionStorage ? this.sessionStorageSetItem : this.localStorageSetItem)(constants.LOCAL_STORAGE_SESSION_COOKIE, cookie);
|
|
435
|
-
};
|
|
436
|
-
this.ctx = {
|
|
437
|
-
env,
|
|
438
|
-
apiKey,
|
|
439
|
-
client: (0, userManagementClient_js_1.initClient)({
|
|
440
|
-
env,
|
|
441
|
-
version: ParaCore.version,
|
|
442
|
-
apiKey,
|
|
443
|
-
partnerId: this.isPortal(env) ? opts.portalPartnerId : undefined,
|
|
444
|
-
useFetchAdapter: !!opts.disableWorkers,
|
|
445
|
-
retrieveSessionCookie: this.retrieveSessionCookie,
|
|
446
|
-
persistSessionCookie: this.persistSessionCookie,
|
|
447
|
-
}),
|
|
448
|
-
disableWorkers: opts.disableWorkers,
|
|
449
|
-
offloadMPCComputationURL: opts.offloadMPCComputationURL,
|
|
450
|
-
useLocalFiles: opts.useLocalFiles,
|
|
451
|
-
useDKLS: opts.useDKLSForCreation || !opts.offloadMPCComputationURL,
|
|
452
|
-
disableWebSockets: !!opts.disableWebSockets,
|
|
453
|
-
wasmOverride: opts.wasmOverride,
|
|
454
|
-
cosmosPrefix: this.cosmosPrefix,
|
|
455
|
-
};
|
|
456
|
-
if (opts.offloadMPCComputationURL) {
|
|
457
|
-
this.ctx.mpcComputationClient = mpcComputationClient.initClient(opts.offloadMPCComputationURL, opts.disableWorkers);
|
|
458
|
-
}
|
|
459
|
-
// Support legacy supportedWalletTypes
|
|
460
|
-
try {
|
|
461
|
-
__classPrivateFieldSet(this, _ParaCore_supportedWalletTypes, opts.supportedWalletTypes
|
|
462
|
-
? (() => {
|
|
463
|
-
if (Object.values(opts.supportedWalletTypes).every(config => !!config && typeof config === 'object' && config.optional)) {
|
|
464
|
-
throw new Error('at least one wallet type must be non-optional');
|
|
465
|
-
}
|
|
466
|
-
if (!Object.keys(opts.supportedWalletTypes).every(type => Object.values(user_management_client_1.WalletType).includes(type))) {
|
|
467
|
-
throw new Error('unsupported wallet type');
|
|
468
|
-
}
|
|
469
|
-
__classPrivateFieldSet(this, _ParaCore_supportedWalletTypesOpt, opts.supportedWalletTypes, "f");
|
|
470
|
-
return Object.entries(opts.supportedWalletTypes).reduce((acc, [key, value]) => {
|
|
471
|
-
var _a;
|
|
472
|
-
if (!value) {
|
|
473
|
-
return acc;
|
|
474
|
-
}
|
|
475
|
-
if (key === user_management_client_1.WalletType.COSMOS &&
|
|
476
|
-
typeof value === 'object' &&
|
|
477
|
-
!!value.prefix) {
|
|
478
|
-
this.cosmosPrefix = value.prefix;
|
|
479
|
-
}
|
|
480
|
-
return [...acc, { type: key, optional: value === true ? false : ((_a = value.optional) !== null && _a !== void 0 ? _a : false) }];
|
|
481
|
-
}, []);
|
|
482
|
-
})()
|
|
483
|
-
: undefined, "f");
|
|
484
|
-
}
|
|
485
|
-
catch (e) {
|
|
486
|
-
__classPrivateFieldSet(this, _ParaCore_supportedWalletTypes, undefined, "f");
|
|
487
|
-
}
|
|
488
|
-
if (!this.platformUtils.isSyncStorage || opts.useStorageOverrides) {
|
|
489
|
-
return;
|
|
490
|
-
}
|
|
491
|
-
this.email = this.localStorageGetItem(constants.LOCAL_STORAGE_EMAIL) || undefined;
|
|
492
|
-
this.countryCode = this.localStorageGetItem(constants.LOCAL_STORAGE_COUNTRY_CODE) || undefined;
|
|
493
|
-
this.phone = this.localStorageGetItem(constants.LOCAL_STORAGE_PHONE) || undefined;
|
|
494
|
-
this.userId = this.localStorageGetItem(constants.LOCAL_STORAGE_USER_ID) || undefined;
|
|
495
|
-
this.telegramUserId = this.localStorageGetItem(constants.LOCAL_STORAGE_TELEGRAM_USER_ID) || undefined;
|
|
496
|
-
const stringWallets = this.platformUtils.secureStorage
|
|
497
|
-
? this.platformUtils.secureStorage.get(constants.LOCAL_STORAGE_WALLETS)
|
|
498
|
-
: this.localStorageGetItem(constants.LOCAL_STORAGE_WALLETS);
|
|
499
|
-
const _wallets = JSON.parse(stringWallets || '{}');
|
|
500
|
-
const stringEd25519Wallets = this.platformUtils.secureStorage
|
|
501
|
-
? this.platformUtils.secureStorage.get(constants.LOCAL_STORAGE_ED25519_WALLETS)
|
|
502
|
-
: this.localStorageGetItem(constants.LOCAL_STORAGE_ED25519_WALLETS);
|
|
503
|
-
const _ed25519Wallets = JSON.parse(stringEd25519Wallets || '{}');
|
|
504
|
-
const wallets = Object.assign(Object.assign({}, Object.keys(_wallets).reduce((res, key) => {
|
|
505
|
-
return Object.assign(Object.assign({}, res), { [key]: (0, index_js_2.migrateWallet)(_wallets[key]) });
|
|
506
|
-
}, {})), Object.keys(_ed25519Wallets).reduce((res, key) => {
|
|
507
|
-
return Object.assign(Object.assign({}, res), (!res[key] ? { [key]: (0, index_js_2.migrateWallet)(_ed25519Wallets[key]) } : {}));
|
|
508
|
-
}, {}));
|
|
509
|
-
this.setWallets(wallets);
|
|
510
|
-
// TODO: Improve not great check
|
|
511
|
-
const _currentWalletIds = (_a = this.localStorageGetItem(constants.LOCAL_STORAGE_CURRENT_WALLET_IDS)) !== null && _a !== void 0 ? _a : undefined;
|
|
512
|
-
const currentWalletIds = [undefined, null, 'undefined'].includes(_currentWalletIds)
|
|
513
|
-
? {}
|
|
514
|
-
: (() => {
|
|
515
|
-
const fromJson = JSON.parse(_currentWalletIds);
|
|
516
|
-
return Array.isArray(fromJson)
|
|
517
|
-
? Object.keys(user_management_client_1.WalletType).reduce((acc, type) => {
|
|
518
|
-
const wallet = Object.values(this.wallets).find(w => fromJson.includes(w.id) && index_js_2.WalletSchemeTypeMap[w.scheme][type]);
|
|
519
|
-
return Object.assign(Object.assign({}, acc), (wallet && !acc[type] ? { [type]: [wallet.id] } : {}));
|
|
520
|
-
}, {})
|
|
521
|
-
: fromJson;
|
|
522
|
-
})();
|
|
523
|
-
this.setCurrentWalletIds(currentWalletIds);
|
|
524
|
-
// TODO: remove sessionStorageGetItem call once new version is being consumed
|
|
525
|
-
this.sessionCookie =
|
|
526
|
-
this.localStorageGetItem(constants.LOCAL_STORAGE_SESSION_COOKIE) ||
|
|
527
|
-
this.sessionStorageGetItem(constants.LOCAL_STORAGE_SESSION_COOKIE) ||
|
|
528
|
-
undefined;
|
|
529
|
-
// In case currentWalletIds was missing from storage
|
|
530
|
-
if (Object.values(this.wallets).filter(w => this.isWalletOwned(w)).length > 0 &&
|
|
531
|
-
this.currentWalletIdsArray.length === 0) {
|
|
532
|
-
this.findWalletId(undefined, { forbidPregen: true });
|
|
533
|
-
}
|
|
534
|
-
const loginEncryptionKey = this.sessionStorageGetItem(constants.SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR);
|
|
535
|
-
if (loginEncryptionKey && loginEncryptionKey !== 'undefined') {
|
|
536
|
-
this.loginEncryptionKeyPair = this.convertEncryptionKeyPair(JSON.parse(loginEncryptionKey));
|
|
537
|
-
}
|
|
538
|
-
const stringExternalWallets = this.localStorageGetItem(constants.LOCAL_STORAGE_EXTERNAL_WALLETS);
|
|
539
|
-
const _externalWallets = JSON.parse(stringExternalWallets || '{}');
|
|
540
|
-
this.setExternalWallets(_externalWallets);
|
|
541
|
-
const _currentExternalWalletAddresses = this.localStorageGetItem(constants.LOCAL_STORAGE_CURRENT_EXTERNAL_WALLET_ADDRESSES) || undefined;
|
|
542
|
-
this.currentExternalWalletAddresses = _currentExternalWalletAddresses
|
|
543
|
-
? JSON.parse(_currentExternalWalletAddresses)
|
|
544
|
-
: undefined;
|
|
545
|
-
}
|
|
546
|
-
touchSession(regenerate = false) {
|
|
547
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
548
|
-
const res = yield this.ctx.client.touchSession(regenerate);
|
|
549
|
-
this.setSupportedWalletTypes(res.data.supportedWalletTypes, res.data.cosmosPrefix);
|
|
550
|
-
return res;
|
|
551
|
-
});
|
|
552
|
-
}
|
|
553
|
-
setSupportedWalletTypes(supportedWalletTypes, cosmosPrefix) {
|
|
554
|
-
if (supportedWalletTypes && !__classPrivateFieldGet(this, _ParaCore_supportedWalletTypes, "f")) {
|
|
555
|
-
__classPrivateFieldSet(this, _ParaCore_supportedWalletTypes, supportedWalletTypes, "f");
|
|
556
|
-
Object.keys(this.currentWalletIds).forEach((type) => {
|
|
557
|
-
var _a;
|
|
558
|
-
if (!((_a = __classPrivateFieldGet(this, _ParaCore_supportedWalletTypes, "f")) === null || _a === void 0 ? void 0 : _a.some(({ type: supportedType }) => supportedType === type))) {
|
|
559
|
-
delete this.currentWalletIds[type];
|
|
560
|
-
}
|
|
561
|
-
});
|
|
562
|
-
}
|
|
563
|
-
if (cosmosPrefix && !this.cosmosPrefix) {
|
|
564
|
-
this.cosmosPrefix = cosmosPrefix;
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
getVerificationEmailProps() {
|
|
568
|
-
return {
|
|
569
|
-
brandColor: this.emailPrimaryColor,
|
|
570
|
-
theme: this.emailTheme,
|
|
571
|
-
supportUrl: this.supportUrl,
|
|
572
|
-
homepageUrl: this.homepageUrl,
|
|
573
|
-
xUrl: this.xUrl,
|
|
574
|
-
githubUrl: this.githubUrl,
|
|
575
|
-
linkedinUrl: this.linkedinUrl,
|
|
576
|
-
};
|
|
577
|
-
}
|
|
578
|
-
getBackupKitEmailProps() {
|
|
579
|
-
return {
|
|
580
|
-
brandColor: this.emailPrimaryColor,
|
|
581
|
-
theme: this.emailTheme,
|
|
582
|
-
homepageUrl: this.homepageUrl,
|
|
583
|
-
xUrl: this.xUrl,
|
|
584
|
-
linkedinUrl: this.linkedinUrl,
|
|
585
|
-
githubUrl: this.githubUrl,
|
|
586
|
-
supportUrl: this.supportUrl,
|
|
587
|
-
};
|
|
588
|
-
}
|
|
589
|
-
/**
|
|
590
|
-
* Initialize storage relating to a `ParaCore` instance.
|
|
591
|
-
*
|
|
592
|
-
* Init only needs to be called for storage that is async.
|
|
593
|
-
*/
|
|
594
|
-
init() {
|
|
595
|
-
var _a;
|
|
596
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
597
|
-
this.email = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_EMAIL)) || undefined;
|
|
598
|
-
this.countryCode =
|
|
599
|
-
(yield this.localStorageGetItem(constants.LOCAL_STORAGE_COUNTRY_CODE)) || undefined;
|
|
600
|
-
this.phone = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_PHONE)) || undefined;
|
|
601
|
-
this.userId = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_USER_ID)) || undefined;
|
|
602
|
-
this.telegramUserId =
|
|
603
|
-
(yield this.localStorageGetItem(constants.LOCAL_STORAGE_TELEGRAM_USER_ID)) || undefined;
|
|
604
|
-
const stringWallets = this.platformUtils.secureStorage
|
|
605
|
-
? yield this.platformUtils.secureStorage.get(constants.LOCAL_STORAGE_WALLETS)
|
|
606
|
-
: yield this.localStorageGetItem(constants.LOCAL_STORAGE_WALLETS);
|
|
607
|
-
const _wallets = JSON.parse(stringWallets || '{}');
|
|
608
|
-
const stringEd25519Wallets = this.platformUtils.secureStorage
|
|
609
|
-
? yield this.platformUtils.secureStorage.get(constants.LOCAL_STORAGE_ED25519_WALLETS)
|
|
610
|
-
: yield this.localStorageGetItem(constants.LOCAL_STORAGE_ED25519_WALLETS);
|
|
611
|
-
const _ed25519Wallets = JSON.parse(stringEd25519Wallets || '{}');
|
|
612
|
-
const wallets = Object.assign(Object.assign({}, Object.keys(_wallets).reduce((res, key) => {
|
|
613
|
-
return Object.assign(Object.assign({}, res), { [key]: (0, index_js_2.migrateWallet)(_wallets[key]) });
|
|
614
|
-
}, {})), Object.keys(_ed25519Wallets).reduce((res, key) => {
|
|
615
|
-
return Object.assign(Object.assign({}, res), (!res[key] ? { [key]: (0, index_js_2.migrateWallet)(_ed25519Wallets[key]) } : {}));
|
|
616
|
-
}, {}));
|
|
617
|
-
yield this.setWallets(wallets);
|
|
618
|
-
// TODO: Improve not great check
|
|
619
|
-
const _currentWalletIds = (_a = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_CURRENT_WALLET_IDS))) !== null && _a !== void 0 ? _a : undefined;
|
|
620
|
-
const currentWalletIds = [undefined, null, 'undefined', 'null'].includes(_currentWalletIds)
|
|
621
|
-
? {}
|
|
622
|
-
: (() => {
|
|
623
|
-
const fromJson = JSON.parse(_currentWalletIds);
|
|
624
|
-
return Array.isArray(fromJson)
|
|
625
|
-
? Object.keys(user_management_client_1.WalletType).reduce((acc, type) => {
|
|
626
|
-
const wallet = Object.values(this.wallets).find(w => fromJson.includes(w.id) && index_js_2.WalletSchemeTypeMap[w.scheme][type]);
|
|
627
|
-
return Object.assign(Object.assign({}, acc), (wallet && !acc[type] ? { [type]: [wallet.id] } : {}));
|
|
628
|
-
}, {})
|
|
629
|
-
: fromJson;
|
|
630
|
-
})();
|
|
631
|
-
yield this.setCurrentWalletIds(currentWalletIds);
|
|
632
|
-
// TODO: remove sessionStorageGetItem call once new version is being consumed
|
|
633
|
-
this.sessionCookie =
|
|
634
|
-
(yield this.localStorageGetItem(constants.LOCAL_STORAGE_SESSION_COOKIE)) ||
|
|
635
|
-
(yield this.sessionStorageGetItem(constants.LOCAL_STORAGE_SESSION_COOKIE)) ||
|
|
636
|
-
undefined;
|
|
637
|
-
// In case currentWalletIds was missing from storage
|
|
638
|
-
if (Object.values(this.wallets).filter(w => this.isWalletOwned(w)).length > 0 &&
|
|
639
|
-
this.currentWalletIdsArray.length === 0) {
|
|
640
|
-
this.findWalletId(undefined, { forbidPregen: true });
|
|
641
|
-
}
|
|
642
|
-
const loginEncryptionKey = (yield this.sessionStorageGetItem(constants.SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR));
|
|
643
|
-
if (loginEncryptionKey && loginEncryptionKey !== 'undefined') {
|
|
644
|
-
this.loginEncryptionKeyPair = this.convertEncryptionKeyPair(JSON.parse(loginEncryptionKey));
|
|
645
|
-
}
|
|
646
|
-
const stringExternalWallets = yield this.localStorageGetItem(constants.LOCAL_STORAGE_EXTERNAL_WALLETS);
|
|
647
|
-
const _externalWallets = JSON.parse(stringExternalWallets || '{}');
|
|
648
|
-
yield this.setExternalWallets(_externalWallets);
|
|
649
|
-
const _currentExternalWalletAddresses = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_CURRENT_EXTERNAL_WALLET_ADDRESSES)) || undefined;
|
|
650
|
-
this.currentExternalWalletAddresses = _currentExternalWalletAddresses
|
|
651
|
-
? JSON.parse(_currentExternalWalletAddresses)
|
|
652
|
-
: undefined;
|
|
653
|
-
yield this.touchSession();
|
|
654
|
-
});
|
|
655
|
-
}
|
|
656
|
-
/**
|
|
657
|
-
* Sets the email associated with the `ParaCore` instance.
|
|
658
|
-
* @param email - Email to set.
|
|
659
|
-
*/
|
|
660
|
-
setEmail(email) {
|
|
661
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
662
|
-
this.email = email;
|
|
663
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_EMAIL, email);
|
|
664
|
-
});
|
|
665
|
-
}
|
|
666
|
-
/**
|
|
667
|
-
* Sets the Telegram user ID associated with the `ParaCore` instance.
|
|
668
|
-
* @param telegramUserId - Telegram user ID to set.
|
|
669
|
-
*/
|
|
670
|
-
setTelegramUserId(telegramUserId) {
|
|
671
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
672
|
-
this.telegramUserId = telegramUserId;
|
|
673
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_TELEGRAM_USER_ID, telegramUserId);
|
|
674
|
-
});
|
|
675
|
-
}
|
|
676
|
-
/**
|
|
677
|
-
* Sets the phone number associated with the `ParaCore` instance.
|
|
678
|
-
* @param phone - Phone number to set.
|
|
679
|
-
* @param countryCode - Country Code to set.
|
|
680
|
-
*/
|
|
681
|
-
setPhoneNumber(phone, countryCode) {
|
|
682
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
683
|
-
this.phone = phone;
|
|
684
|
-
this.countryCode = countryCode;
|
|
685
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_PHONE, phone);
|
|
686
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_COUNTRY_CODE, countryCode);
|
|
687
|
-
});
|
|
688
|
-
}
|
|
689
|
-
/**
|
|
690
|
-
* Sets the farcaster username associated with the `ParaCore` instance.
|
|
691
|
-
* @param farcasterUsername - Farcaster Username to set.
|
|
692
|
-
*/
|
|
693
|
-
setFarcasterUsername(farcasterUsername) {
|
|
694
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
695
|
-
this.farcasterUsername = farcasterUsername;
|
|
696
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_FARCASTER_USERNAME, farcasterUsername);
|
|
697
|
-
});
|
|
698
|
-
}
|
|
699
|
-
/**
|
|
700
|
-
* Sets the external wallet address and type associated with the `ParaCore` instance.
|
|
701
|
-
* @param externalAddress - External wallet address to set.
|
|
702
|
-
* @param externalType - Type of external wallet to set.
|
|
703
|
-
*/
|
|
704
|
-
setExternalWallet({ address, type, provider, addressBech32 }) {
|
|
705
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
706
|
-
// Can change this to continue storing existing external wallets if/when we want to allow multiple connected external wallets
|
|
707
|
-
this.externalWallets = {
|
|
708
|
-
[address]: {
|
|
709
|
-
id: address,
|
|
710
|
-
address: addressBech32 !== null && addressBech32 !== void 0 ? addressBech32 : address,
|
|
711
|
-
type,
|
|
712
|
-
name: provider,
|
|
713
|
-
isExternal: true,
|
|
714
|
-
signer: '',
|
|
715
|
-
},
|
|
716
|
-
};
|
|
717
|
-
this.currentExternalWalletAddresses = [address];
|
|
718
|
-
this.setCurrentExternalWalletAddresses(this.currentExternalWalletAddresses);
|
|
719
|
-
this.setExternalWallets(this.externalWallets);
|
|
720
|
-
(0, index_js_2.dispatchEvent)(index_js_1.ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, null);
|
|
721
|
-
});
|
|
722
|
-
}
|
|
723
|
-
/**
|
|
724
|
-
* Sets the user id associated with the `ParaCore` instance.
|
|
725
|
-
* @param userId - User id to set.
|
|
726
|
-
*/
|
|
727
|
-
setUserId(userId) {
|
|
728
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
729
|
-
this.userId = userId;
|
|
730
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_USER_ID, userId);
|
|
731
|
-
});
|
|
732
|
-
}
|
|
733
|
-
/**
|
|
734
|
-
* Sets the wallets associated with the `ParaCore` instance.
|
|
735
|
-
* @param wallets - Wallets to set.
|
|
736
|
-
*/
|
|
737
|
-
setWallets(wallets) {
|
|
738
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
739
|
-
this.wallets = wallets;
|
|
740
|
-
if (this.platformUtils.secureStorage) {
|
|
741
|
-
yield this.platformUtils.secureStorage.set(constants.LOCAL_STORAGE_WALLETS, JSON.stringify(wallets));
|
|
742
|
-
return;
|
|
743
|
-
}
|
|
744
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_WALLETS, JSON.stringify(wallets));
|
|
745
|
-
});
|
|
746
|
-
}
|
|
747
|
-
/**
|
|
748
|
-
* Sets the external wallets associated with the `ParaCore` instance.
|
|
749
|
-
* @param externalWallets - External wallets to set.
|
|
750
|
-
*/
|
|
751
|
-
setExternalWallets(externalWallets) {
|
|
752
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
753
|
-
this.externalWallets = externalWallets;
|
|
754
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_EXTERNAL_WALLETS, JSON.stringify(externalWallets));
|
|
755
|
-
});
|
|
756
|
-
}
|
|
757
|
-
setCurrentExternalWalletAddresses(currentExternalWalletAddresses) {
|
|
758
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
759
|
-
this.currentExternalWalletAddresses = currentExternalWalletAddresses;
|
|
760
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_CURRENT_EXTERNAL_WALLET_ADDRESSES, JSON.stringify(currentExternalWalletAddresses));
|
|
761
|
-
});
|
|
762
|
-
}
|
|
763
|
-
/**
|
|
764
|
-
* Sets the login encryption key pair associated with the `ParaCore` instance.
|
|
765
|
-
* @param keyPair - Encryption key pair generated from loginEncryptionKey.
|
|
766
|
-
*/
|
|
767
|
-
setLoginEncryptionKeyPair(keyPair) {
|
|
768
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
769
|
-
if (!keyPair) {
|
|
770
|
-
keyPair = yield (0, utils_js_1.getAsymmetricKeyPair)(this.ctx);
|
|
771
|
-
}
|
|
772
|
-
this.loginEncryptionKeyPair = keyPair;
|
|
773
|
-
yield this.sessionStorageSetItem(constants.SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR, JSON.stringify(keyPair));
|
|
774
|
-
});
|
|
775
|
-
}
|
|
776
|
-
deleteLoginEncryptionKeyPair() {
|
|
777
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
778
|
-
this.loginEncryptionKeyPair = undefined;
|
|
779
|
-
yield this.sessionStorageRemoveItem(constants.SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR);
|
|
780
|
-
});
|
|
781
|
-
}
|
|
782
|
-
/**
|
|
783
|
-
* Gets the userId associated with the `ParaCore` instance.
|
|
784
|
-
* @returns - userId associated with the `ParaCore` instance.
|
|
785
|
-
*/
|
|
786
|
-
getUserId() {
|
|
787
|
-
return this.userId;
|
|
788
|
-
}
|
|
789
|
-
/**
|
|
790
|
-
* Gets the email associated with the `ParaCore` instance.
|
|
791
|
-
* @returns - email associated with the `ParaCore` instance.
|
|
792
|
-
*/
|
|
793
|
-
getEmail() {
|
|
794
|
-
return this.email;
|
|
795
|
-
}
|
|
796
|
-
/**
|
|
797
|
-
* Gets the phone object associated with the `ParaCore` instance.
|
|
798
|
-
* @returns - phone object with phone number and country code associated with the `ParaCore` instance.
|
|
799
|
-
*/
|
|
800
|
-
getPhone() {
|
|
801
|
-
return { phone: this.phone, countryCode: this.countryCode };
|
|
802
|
-
}
|
|
803
|
-
/**
|
|
804
|
-
* Gets the formatted phone number associated with the `ParaCore` instance.
|
|
805
|
-
* @returns - formatted phone number associated with the `ParaCore` instance.
|
|
806
|
-
*/
|
|
807
|
-
getPhoneNumber() {
|
|
808
|
-
if (!this.phone || !this.countryCode) {
|
|
809
|
-
return undefined;
|
|
810
|
-
}
|
|
811
|
-
return (0, index_js_2.normalizePhoneNumber)(this.countryCode, this.phone);
|
|
812
|
-
}
|
|
813
|
-
/**
|
|
814
|
-
* Gets the farcaster username associated with the `ParaCore` instance.
|
|
815
|
-
* @returns - farcaster username associated with the `ParaCore` instance.
|
|
816
|
-
*/
|
|
817
|
-
getFarcasterUsername() {
|
|
818
|
-
return this.farcasterUsername;
|
|
819
|
-
}
|
|
820
|
-
setCurrentWalletIds(currentWalletIds, { needsWallet = false, sessionLookupId, newDeviceSessionLookupId, } = {}) {
|
|
821
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
822
|
-
this.currentWalletIds = currentWalletIds;
|
|
823
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_CURRENT_WALLET_IDS, JSON.stringify(this.currentWalletIds));
|
|
824
|
-
if (sessionLookupId) {
|
|
825
|
-
yield this.ctx.client.setCurrentWalletIds(this.getUserId(), this.currentWalletIds, needsWallet, sessionLookupId, newDeviceSessionLookupId);
|
|
826
|
-
}
|
|
827
|
-
(0, index_js_2.dispatchEvent)(index_js_1.ParaEvent.WALLETS_CHANGE_EVENT, null);
|
|
828
|
-
});
|
|
829
|
-
}
|
|
830
|
-
/**
|
|
831
|
-
* Validates that a wallet ID is present on the instance, usable, and matches the desired filters.
|
|
832
|
-
* If no ID is passed, this will instead return the first valid, usable wallet ID that matches the filters.
|
|
833
|
-
* @param {string} [walletId] the wallet ID to validate.
|
|
834
|
-
* @param {WalletFilters} [filter={}] a `WalletFilters` object specifying allowed types, schemes, and whether to forbid unclaimed pregen wallets.
|
|
835
|
-
* @returns {string} the wallet ID originally passed, or the one found.
|
|
836
|
-
*/
|
|
837
|
-
findWalletId(walletId, filter = {}) {
|
|
838
|
-
if (walletId) {
|
|
839
|
-
this.assertIsValidWalletId(walletId, filter);
|
|
840
|
-
}
|
|
841
|
-
else {
|
|
842
|
-
for (const id of [...this.currentWalletIdsUnique, ...Object.keys(this.wallets)]) {
|
|
843
|
-
if (this.isWalletUsable(id, filter)) {
|
|
844
|
-
walletId = id;
|
|
845
|
-
break;
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
if (!walletId) {
|
|
849
|
-
throw new Error(`no valid wallet id found`);
|
|
850
|
-
}
|
|
851
|
-
}
|
|
852
|
-
return walletId;
|
|
853
|
-
}
|
|
854
|
-
/**
|
|
855
|
-
* Retrieves a wallet with the given address, if present.
|
|
856
|
-
* If no ID is passed, this will instead return the first valid, usable wallet ID that matches the filters.
|
|
857
|
-
* @param {string} [walletId] the wallet ID to validate.
|
|
858
|
-
* @param {WalletFilters} [filter={}] a `WalletFilters` object specifying allowed types, schemes, and whether to forbid unclaimed pregen wallets.
|
|
859
|
-
* @returns {string} the wallet ID originally passed, or the one found.
|
|
860
|
-
*/
|
|
861
|
-
findWalletByAddress(address, filter) {
|
|
862
|
-
if (this.externalWallets[address]) {
|
|
863
|
-
return this.externalWallets[address];
|
|
864
|
-
}
|
|
865
|
-
let wallet;
|
|
866
|
-
Object.entries(this.currentWalletIds).forEach(([type, walletIds]) => {
|
|
867
|
-
const pregenWalletIds = Object.keys(this.wallets).filter(id => this.wallets[id].type === type && this.isPregenWalletClaimable(this.wallets[id]));
|
|
868
|
-
[...walletIds, ...pregenWalletIds].forEach(id => {
|
|
869
|
-
if (address.toLowerCase() === this.getDisplayAddress(id, { addressType: type }).toLowerCase()) {
|
|
870
|
-
wallet = this.wallets[id];
|
|
871
|
-
}
|
|
872
|
-
});
|
|
873
|
-
});
|
|
874
|
-
if (!wallet) {
|
|
875
|
-
throw new Error(`wallet with address ${address} not found`);
|
|
876
|
-
}
|
|
877
|
-
this.assertIsValidWalletId(wallet.id, filter);
|
|
878
|
-
return wallet;
|
|
879
|
-
}
|
|
880
|
-
findWallet(idOrAddress, overrideType, filter = {}) {
|
|
881
|
-
var _a, _b;
|
|
882
|
-
if (!idOrAddress && Object.keys(this.externalWallets).length > 0) {
|
|
883
|
-
return Object.values(this.externalWallets)[0];
|
|
884
|
-
}
|
|
885
|
-
if (this.externalWallets[idOrAddress]) {
|
|
886
|
-
return this.externalWallets[idOrAddress];
|
|
887
|
-
}
|
|
888
|
-
try {
|
|
889
|
-
const walletId = this.findWalletId(idOrAddress, filter);
|
|
890
|
-
if (walletId && !!this.wallets[walletId]) {
|
|
891
|
-
const _c = this.wallets[walletId], { signer: _signer } = _c, wallet = __rest(_c, ["signer"]);
|
|
892
|
-
const type = (_b = overrideType !== null && overrideType !== void 0 ? overrideType : (_a = this.currentWalletIdsArray.find(([id]) => id === walletId)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : wallet.type;
|
|
893
|
-
return Object.assign(Object.assign({}, wallet), { type: user_management_client_1.WalletType[type] });
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
catch (e) {
|
|
897
|
-
return undefined;
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
get availableWallets() {
|
|
901
|
-
var _a;
|
|
902
|
-
return [
|
|
903
|
-
...this.currentWalletIdsArray
|
|
904
|
-
.map(([address, type]) => [address, type, false])
|
|
905
|
-
.map(([id, type]) => {
|
|
906
|
-
const wallet = this.findWallet(id, type);
|
|
907
|
-
if (!wallet)
|
|
908
|
-
return null;
|
|
909
|
-
return {
|
|
910
|
-
id: wallet.id,
|
|
911
|
-
type,
|
|
912
|
-
address: this.getDisplayAddress(id, { addressType: type }),
|
|
913
|
-
name: wallet.name,
|
|
914
|
-
};
|
|
915
|
-
})
|
|
916
|
-
.filter(obj => obj !== null),
|
|
917
|
-
...Object.values((_a = this.externalWallets) !== null && _a !== void 0 ? _a : {}),
|
|
918
|
-
];
|
|
919
|
-
}
|
|
920
|
-
/**
|
|
921
|
-
* Retrieves all usable wallets with the provided type (`'EVM' | 'COSMOS' | 'SOLANA'`)
|
|
922
|
-
* @param {string} type the wallet type to filter by.
|
|
923
|
-
* @returns {Wallet[]} an array of matching wallets.
|
|
924
|
-
*/
|
|
925
|
-
getWalletsByType(type) {
|
|
926
|
-
return Object.values(this.wallets).filter(w => this.isWalletUsable(w.id, { type: [type] }));
|
|
927
|
-
}
|
|
928
|
-
assertIsValidWalletId(walletId, condition = {}) {
|
|
929
|
-
this.isWalletUsable(walletId, condition, true);
|
|
930
|
-
}
|
|
931
|
-
assertIsValidWalletType(type, walletTypes) {
|
|
932
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
933
|
-
if (!__classPrivateFieldGet(this, _ParaCore_supportedWalletTypes, "f")) {
|
|
934
|
-
yield this.touchSession();
|
|
935
|
-
}
|
|
936
|
-
if (!type ||
|
|
937
|
-
!Object.values(user_management_client_1.WalletType).includes(type) ||
|
|
938
|
-
!(walletTypes !== null && walletTypes !== void 0 ? walletTypes : this.supportedWalletTypes.map(({ type }) => type)).includes(type)) {
|
|
939
|
-
throw new Error(`wallet type ${type} is not supported`);
|
|
940
|
-
}
|
|
941
|
-
return type;
|
|
942
|
-
});
|
|
943
|
-
}
|
|
944
|
-
getMissingTypes() {
|
|
945
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
946
|
-
if (!__classPrivateFieldGet(this, _ParaCore_supportedWalletTypes, "f")) {
|
|
947
|
-
yield this.touchSession();
|
|
948
|
-
}
|
|
949
|
-
return (this.supportedWalletTypes
|
|
950
|
-
.filter(({ type: t, optional }) => !optional && Object.values(this.wallets).every(w => !this.isWalletOwned(w) || !index_js_2.WalletSchemeTypeMap[w.scheme][t]))
|
|
951
|
-
.map(({ type }) => type));
|
|
952
|
-
});
|
|
953
|
-
}
|
|
954
|
-
getTypesToCreate(types) {
|
|
955
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
956
|
-
if (!__classPrivateFieldGet(this, _ParaCore_supportedWalletTypes, "f")) {
|
|
957
|
-
yield this.touchSession();
|
|
958
|
-
}
|
|
959
|
-
return (0, index_js_2.getSchemes)(types !== null && types !== void 0 ? types : (yield this.getMissingTypes())).map(scheme => {
|
|
960
|
-
switch (scheme) {
|
|
961
|
-
case user_management_client_1.WalletScheme.ED25519:
|
|
962
|
-
return user_management_client_1.WalletType.SOLANA;
|
|
963
|
-
default:
|
|
964
|
-
return this.supportedWalletTypes.some(({ type, optional }) => type === user_management_client_1.WalletType.COSMOS && !optional)
|
|
965
|
-
? user_management_client_1.WalletType.COSMOS
|
|
966
|
-
: user_management_client_1.WalletType.EVM;
|
|
967
|
-
}
|
|
968
|
-
});
|
|
969
|
-
});
|
|
970
|
-
}
|
|
971
|
-
getPartnerURL(partnerId) {
|
|
972
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
973
|
-
const res = yield this.ctx.client.getPartner(partnerId);
|
|
974
|
-
return res.data.partner.portalUrl;
|
|
975
|
-
});
|
|
976
|
-
}
|
|
977
|
-
/**
|
|
978
|
-
* URL of the portal, which can be associated with a partner id
|
|
979
|
-
* @param partnerId: string - id of the partner to get the portal URL for
|
|
980
|
-
* @returns - portal URL
|
|
981
|
-
*/
|
|
982
|
-
getPortalURL(partnerId) {
|
|
983
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
984
|
-
return (partnerId && (yield this.getPartnerURL(partnerId))) || (0, index_js_2.getPortalBaseURL)(this.ctx);
|
|
985
|
-
});
|
|
986
|
-
}
|
|
987
|
-
getWebAuthURLForCreate(_a) {
|
|
988
|
-
var { webAuthId } = _a, options = __rest(_a, ["webAuthId"]);
|
|
989
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
990
|
-
return this.constructPortalUrl('createAuth', Object.assign(Object.assign({}, options), { pathId: webAuthId }));
|
|
991
|
-
});
|
|
992
|
-
}
|
|
993
|
-
getPasswordURLForCreate(_a) {
|
|
994
|
-
var { passwordId } = _a, options = __rest(_a, ["passwordId"]);
|
|
995
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
996
|
-
return this.constructPortalUrl('createPassword', Object.assign(Object.assign({}, options), { pathId: passwordId }));
|
|
997
|
-
});
|
|
998
|
-
}
|
|
999
|
-
getShortUrl(compressedUrl) {
|
|
1000
|
-
return (0, index_js_2.constructUrl)({
|
|
1001
|
-
base: (0, index_js_2.getPortalBaseURL)(this.ctx),
|
|
1002
|
-
path: `/short/${compressedUrl}`,
|
|
1003
|
-
});
|
|
1004
|
-
}
|
|
1005
|
-
shortenLoginLink(link) {
|
|
1006
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1007
|
-
const url = yield transmissionUtils.upload(link, this.ctx.client);
|
|
1008
|
-
return this.getShortUrl(url);
|
|
1009
|
-
});
|
|
1010
|
-
}
|
|
1011
|
-
/**
|
|
1012
|
-
* Generates a URL for registering a new WebAuth passkey.
|
|
1013
|
-
* @param {GetWebAuthUrlForLoginParams} opts the options object
|
|
1014
|
-
* @returns - the URL for creating a new passkey
|
|
1015
|
-
*/
|
|
1016
|
-
getWebAuthURLForLogin(opts) {
|
|
1017
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1018
|
-
return this.constructPortalUrl('loginAuth', opts);
|
|
1019
|
-
});
|
|
1020
|
-
}
|
|
1021
|
-
/**
|
|
1022
|
-
* Generates a URL for registering a new user password.
|
|
1023
|
-
* @param {GetWebAuthUrlForLoginParams} opts the options object
|
|
1024
|
-
* @returns - the URL for creating a new password
|
|
1025
|
-
*/
|
|
1026
|
-
getPasswordURLForLogin(opts) {
|
|
1027
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1028
|
-
return this.constructPortalUrl('loginPassword', opts);
|
|
1029
|
-
});
|
|
1030
|
-
}
|
|
1031
|
-
/**
|
|
1032
|
-
* Generates a URL for registering a new WebAuth passkey for a phone number.
|
|
1033
|
-
* @param {Omit<GetWebAuthUrlForLoginParams, 'authType'>} opts the options object
|
|
1034
|
-
* @returns - web auth url
|
|
1035
|
-
*/
|
|
1036
|
-
getWebAuthURLForLoginForPhone(opts) {
|
|
1037
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1038
|
-
return this.constructPortalUrl('loginAuth', Object.assign({ authType: 'phone' }, opts));
|
|
1039
|
-
});
|
|
1040
|
-
}
|
|
1041
|
-
/**
|
|
1042
|
-
* Gets the private key for the given wallet.
|
|
1043
|
-
* @param {string } [walletId] id of the wallet to get the private key for. Will default to the first wallet if not provided.
|
|
1044
|
-
* @returns - the private key string.
|
|
1045
|
-
*/
|
|
1046
|
-
getPrivateKey(walletId) {
|
|
1047
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1048
|
-
const wallets = Object.values(this.wallets);
|
|
1049
|
-
const wallet = walletId ? this.wallets[walletId] : wallets === null || wallets === void 0 ? void 0 : wallets[0];
|
|
1050
|
-
if (!wallet) {
|
|
1051
|
-
throw new Error('wallet not found');
|
|
1052
|
-
}
|
|
1053
|
-
// We can only build the private key for DKLS wallets
|
|
1054
|
-
if (wallet.scheme !== user_management_client_1.WalletScheme.DKLS) {
|
|
1055
|
-
throw new Error('invalid wallet scheme');
|
|
1056
|
-
}
|
|
1057
|
-
return yield this.platformUtils.getPrivateKey(this.ctx, this.userId, wallet.id, wallet.signer, this.retrieveSessionCookie());
|
|
1058
|
-
});
|
|
1059
|
-
}
|
|
1060
|
-
/**
|
|
1061
|
-
* Fetches the wallets associated with the user.
|
|
1062
|
-
* @returns {WalletEntity[]} wallets that were fetched.
|
|
1063
|
-
*/
|
|
1064
|
-
fetchWallets() {
|
|
1065
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1066
|
-
const res = yield (this.isPortal() || this.isParaConnect()
|
|
1067
|
-
? this.ctx.client.getAllWallets(this.userId)
|
|
1068
|
-
: this.ctx.client.getWallets(this.userId, true));
|
|
1069
|
-
return res.data.wallets.filter(wallet => !!wallet.address &&
|
|
1070
|
-
(this.isParaConnect() || (!this.isParaConnect() && this.isWalletSupported((0, index_js_2.entityToWallet)(wallet)))));
|
|
1071
|
-
});
|
|
1072
|
-
}
|
|
1073
|
-
populateWalletAddresses() {
|
|
1074
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1075
|
-
const res = yield this.ctx.client.getWallets(this.userId, true);
|
|
1076
|
-
const wallets = res.data.wallets;
|
|
1077
|
-
wallets.forEach(entity => {
|
|
1078
|
-
if (this.wallets[entity.id]) {
|
|
1079
|
-
this.wallets[entity.id] = Object.assign(Object.assign({}, (0, index_js_2.entityToWallet)(entity)), this.wallets[entity.id]);
|
|
1080
|
-
}
|
|
1081
|
-
});
|
|
1082
|
-
yield this.setWallets(this.wallets);
|
|
1083
|
-
});
|
|
1084
|
-
}
|
|
1085
|
-
populatePregenWalletAddresses() {
|
|
1086
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1087
|
-
const res = yield this.getPregenWallets();
|
|
1088
|
-
res.forEach(entity => {
|
|
1089
|
-
if (this.wallets[entity.id]) {
|
|
1090
|
-
this.wallets[entity.id] = Object.assign(Object.assign({}, (0, index_js_2.entityToWallet)(entity)), this.wallets[entity.id]);
|
|
1091
|
-
}
|
|
1092
|
-
});
|
|
1093
|
-
yield this.setWallets(this.wallets);
|
|
1094
|
-
});
|
|
1095
|
-
}
|
|
1096
|
-
/**
|
|
1097
|
-
* Checks if a user exists for an email address.
|
|
1098
|
-
* @param {Object} opts the options object
|
|
1099
|
-
* @param {string} opts.email the email to check.
|
|
1100
|
-
* @returns true if user exists, false otherwise.
|
|
1101
|
-
*/
|
|
1102
|
-
checkIfUserExists({ email }) {
|
|
1103
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1104
|
-
const res = yield this.ctx.client.checkUserExists({ email });
|
|
1105
|
-
return res.data.exists;
|
|
1106
|
-
});
|
|
1107
|
-
}
|
|
1108
|
-
/**
|
|
1109
|
-
* Checks if a user exists for a phone number.
|
|
1110
|
-
* @param {Object} opts the options object
|
|
1111
|
-
* @param {string} opts.phone - phone number to check.
|
|
1112
|
-
* @param {string} opts.countryCode - the country code.
|
|
1113
|
-
* @returns true if user exists, false otherwise.
|
|
1114
|
-
*/
|
|
1115
|
-
checkIfUserExistsByPhone({ phone, countryCode }) {
|
|
1116
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1117
|
-
const res = yield this.ctx.client.checkUserExists({ phone, countryCode });
|
|
1118
|
-
return res.data.exists;
|
|
1119
|
-
});
|
|
1120
|
-
}
|
|
1121
|
-
/**
|
|
1122
|
-
* Creates a new user.
|
|
1123
|
-
* @param {Object} opts the options object
|
|
1124
|
-
* @param {string} opts.email the email to use.
|
|
1125
|
-
*/
|
|
1126
|
-
createUser({ email }) {
|
|
1127
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1128
|
-
this.requireApiKey();
|
|
1129
|
-
yield this.setEmail(email);
|
|
1130
|
-
const { userId } = yield this.ctx.client.createUser(Object.assign({ email: this.email }, this.getVerificationEmailProps()));
|
|
1131
|
-
yield this.setUserId(userId);
|
|
1132
|
-
});
|
|
1133
|
-
}
|
|
1134
|
-
/**
|
|
1135
|
-
* Creates a new user with a phone number.
|
|
1136
|
-
* @param {Object} opts the options object
|
|
1137
|
-
* @param {string} opts.phone - the phone number to use for creating the user.
|
|
1138
|
-
* @param {string} opts.countryCode - the country code to use for creating the user.
|
|
1139
|
-
*/
|
|
1140
|
-
createUserByPhone({ phone, countryCode }) {
|
|
1141
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1142
|
-
this.requireApiKey();
|
|
1143
|
-
yield this.setPhoneNumber(phone, countryCode);
|
|
1144
|
-
const { userId } = yield this.ctx.client.createUser({
|
|
1145
|
-
phone: this.phone,
|
|
1146
|
-
countryCode: this.countryCode,
|
|
1147
|
-
});
|
|
1148
|
-
yield this.setUserId(userId);
|
|
1149
|
-
});
|
|
1150
|
-
}
|
|
1151
|
-
/**
|
|
1152
|
-
* Logs in or creates a new user using an external wallet address.
|
|
1153
|
-
* @param {Object} opts the options object
|
|
1154
|
-
* @param {string} opts.address the external wallet address to use for identification.
|
|
1155
|
-
* @param {WalletType} opts.type type of external wallet to use for identification.
|
|
1156
|
-
* @param {string} opts.provider the name of the provider for the external wallet.
|
|
1157
|
-
*/
|
|
1158
|
-
externalWalletLogin(wallet) {
|
|
1159
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1160
|
-
this.requireApiKey();
|
|
1161
|
-
const { userId } = yield this.ctx.client.externalWalletLogin({
|
|
1162
|
-
externalAddress: wallet.address,
|
|
1163
|
-
type: wallet.type,
|
|
1164
|
-
externalWalletProvider: wallet.provider,
|
|
1165
|
-
});
|
|
1166
|
-
yield this.setExternalWallet(wallet);
|
|
1167
|
-
yield this.setUserId(userId);
|
|
1168
|
-
});
|
|
1169
|
-
}
|
|
1170
|
-
/**
|
|
1171
|
-
* Returns whether or not the user is connected with an external wallet.
|
|
1172
|
-
*/
|
|
1173
|
-
isUsingExternalWallet() {
|
|
1174
|
-
return !!Object.keys(this.externalWallets).length;
|
|
1175
|
-
}
|
|
1176
|
-
/**
|
|
1177
|
-
* Passes the email code obtained from the user for verification.
|
|
1178
|
-
* @param {Object} opts the options object
|
|
1179
|
-
* @param {string} verificationCode the six-digit code to check
|
|
1180
|
-
* @returns {string} the web auth url for creating a new credential
|
|
1181
|
-
*/
|
|
1182
|
-
verifyEmail({ verificationCode }) {
|
|
1183
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1184
|
-
yield this.ctx.client.verifyEmail(this.userId, { verificationCode });
|
|
1185
|
-
return this.getSetUpBiometricsURL();
|
|
1186
|
-
});
|
|
1187
|
-
}
|
|
1188
|
-
/**
|
|
1189
|
-
* Passes the phone code obtained from the user for verification.
|
|
1190
|
-
* @param {Object} opts the options object
|
|
1191
|
-
* @param {string} verificationCode the six-digit code to check
|
|
1192
|
-
* @returns {string} the web auth url for creating a new credential
|
|
1193
|
-
*/
|
|
1194
|
-
verifyPhone({ verificationCode }) {
|
|
1195
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1196
|
-
yield this.ctx.client.verifyPhone(this.userId, { verificationCode });
|
|
1197
|
-
return this.getSetUpBiometricsURLForPhone();
|
|
1198
|
-
});
|
|
1199
|
-
}
|
|
1200
|
-
/**
|
|
1201
|
-
* Validates the response received from an attempted Telegram login for authenticity, then
|
|
1202
|
-
* creates or retrieves the corresponding Para user and prepares the Para instance to sign in with that user.
|
|
1203
|
-
* @param authResponse - the response JSON object received from the Telegram widget.
|
|
1204
|
-
* @returns `{ isValid: boolean; telegramUserId?: string; userId?: string; isNewUser?: boolean; supportedAuthMethods?: AuthMethod[]; biometricHints?: BiometricLocationHint[] }`
|
|
1205
|
-
*/
|
|
1206
|
-
verifyTelegram(authObject) {
|
|
1207
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1208
|
-
const res = yield this.ctx.client.verifyTelegram(authObject);
|
|
1209
|
-
if (res.isValid) {
|
|
1210
|
-
yield this.setUserId(res.userId);
|
|
1211
|
-
yield this.setTelegramUserId(res.telegramUserId);
|
|
1212
|
-
yield this.touchSession(true);
|
|
1213
|
-
if (!this.loginEncryptionKeyPair) {
|
|
1214
|
-
yield this.setLoginEncryptionKeyPair();
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1217
|
-
return res;
|
|
1218
|
-
});
|
|
1219
|
-
}
|
|
1220
|
-
/**
|
|
1221
|
-
* Performs 2FA verification.
|
|
1222
|
-
* @param {Object} opts the options object
|
|
1223
|
-
* @param {string} opts.email the email to use for performing a 2FA verification.
|
|
1224
|
-
* @param {string} opts.verificationCode the verification code to received via 2FA.
|
|
1225
|
-
* @returns {Object} `{ address, initiatedAt, status, userId, walletId }`
|
|
1226
|
-
*/
|
|
1227
|
-
verify2FA({ email, verificationCode }) {
|
|
1228
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1229
|
-
const res = yield this.ctx.client.verify2FA(email, verificationCode);
|
|
1230
|
-
return {
|
|
1231
|
-
initiatedAt: res.data.initiatedAt,
|
|
1232
|
-
status: res.data.status,
|
|
1233
|
-
userId: res.data.userId,
|
|
1234
|
-
wallets: res.data.wallets,
|
|
1235
|
-
};
|
|
1236
|
-
});
|
|
1237
|
-
}
|
|
1238
|
-
/**
|
|
1239
|
-
* Performs 2FA verification.
|
|
1240
|
-
* @param {Object} opts the options object
|
|
1241
|
-
* @param {string} opts.phone the phone number
|
|
1242
|
-
* @param {string} opts.countryCode - the country code
|
|
1243
|
-
* @param {string} opts.verificationCode - verification code to received via 2FA.
|
|
1244
|
-
* @returns {Object} `{ address, initiatedAt, status, userId, walletId }`
|
|
1245
|
-
*/
|
|
1246
|
-
verify2FAForPhone({ phone, countryCode, verificationCode, }) {
|
|
1247
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1248
|
-
const res = yield this.ctx.client.verify2FAForPhone(phone, countryCode, verificationCode);
|
|
1249
|
-
return {
|
|
1250
|
-
initiatedAt: res.data.initiatedAt,
|
|
1251
|
-
status: res.data.status,
|
|
1252
|
-
userId: res.data.userId,
|
|
1253
|
-
wallets: res.data.wallets,
|
|
1254
|
-
};
|
|
1255
|
-
});
|
|
1256
|
-
}
|
|
1257
|
-
/**
|
|
1258
|
-
* Sets up two-factor authentication for the current user.
|
|
1259
|
-
* @returns {string} uri - uri to use for setting up 2FA
|
|
1260
|
-
* */
|
|
1261
|
-
setup2FA() {
|
|
1262
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1263
|
-
const res = yield this.ctx.client.setup2FA(this.userId);
|
|
1264
|
-
return {
|
|
1265
|
-
uri: res.data.uri,
|
|
1266
|
-
};
|
|
1267
|
-
});
|
|
1268
|
-
}
|
|
1269
|
-
/**
|
|
1270
|
-
* Enables 2FA.
|
|
1271
|
-
* @param {Object} opts the options object
|
|
1272
|
-
* @param {string} opts.verificationCode - the verification code received via 2FA.
|
|
1273
|
-
*/
|
|
1274
|
-
enable2FA({ verificationCode }) {
|
|
1275
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1276
|
-
yield this.ctx.client.enable2FA(this.userId, verificationCode);
|
|
1277
|
-
});
|
|
1278
|
-
}
|
|
1279
|
-
/**
|
|
1280
|
-
* Determines if 2FA has been set up.
|
|
1281
|
-
* @returns {Object} `{ isSetup: boolean }` - true if 2FA is setup, false otherwise
|
|
1282
|
-
*/
|
|
1283
|
-
check2FAStatus() {
|
|
1284
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1285
|
-
if (!this.userId) {
|
|
1286
|
-
return { isSetup: false };
|
|
1287
|
-
}
|
|
1288
|
-
const res = yield this.ctx.client.check2FAStatus(this.userId);
|
|
1289
|
-
return {
|
|
1290
|
-
isSetup: res.data.isSetup,
|
|
1291
|
-
};
|
|
1292
|
-
});
|
|
1293
|
-
}
|
|
1294
|
-
/**
|
|
1295
|
-
* Resend a verification email for the current user.
|
|
1296
|
-
*/
|
|
1297
|
-
resendVerificationCode() {
|
|
1298
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1299
|
-
yield this.ctx.client.resendVerificationCode(Object.assign({ userId: this.userId }, this.getVerificationEmailProps()));
|
|
1300
|
-
});
|
|
1301
|
-
}
|
|
1302
|
-
/**
|
|
1303
|
-
* Resend a verification SMS for the current user.
|
|
1304
|
-
*/
|
|
1305
|
-
resendVerificationCodeByPhone() {
|
|
1306
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1307
|
-
yield this.ctx.client.resendVerificationCodeByPhone({
|
|
1308
|
-
userId: this.userId,
|
|
1309
|
-
});
|
|
1310
|
-
});
|
|
1311
|
-
}
|
|
1312
|
-
/**
|
|
1313
|
-
* Returns a URL for setting up a new WebAuth passkey.
|
|
1314
|
-
* @param {Object} opts the options object
|
|
1315
|
-
* @param {string} opts.authType - the auth type to use
|
|
1316
|
-
* @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
|
|
1317
|
-
* @returns {string} the URL
|
|
1318
|
-
*/
|
|
1319
|
-
getSetUpBiometricsURL({ authType = 'email', isForNewDevice = false, } = {}) {
|
|
1320
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1321
|
-
const res = yield this.ctx.client.addSessionPublicKey(this.userId, {
|
|
1322
|
-
status: user_management_client_1.PublicKeyStatus.PENDING,
|
|
1323
|
-
type: user_management_client_1.PublicKeyType.WEB,
|
|
1324
|
-
});
|
|
1325
|
-
return this.getWebAuthURLForCreate({
|
|
1326
|
-
authType,
|
|
1327
|
-
isForNewDevice,
|
|
1328
|
-
webAuthId: res.data.id,
|
|
1329
|
-
partnerId: res.data.partnerId,
|
|
1330
|
-
});
|
|
1331
|
-
});
|
|
1332
|
-
}
|
|
1333
|
-
/**
|
|
1334
|
-
* Returns a URL for setting up a new WebAuth passkey for a phone number.
|
|
1335
|
-
* @param {Object} opts the options object
|
|
1336
|
-
* @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
|
|
1337
|
-
* @returns {string} the URL
|
|
1338
|
-
*/
|
|
1339
|
-
getSetUpBiometricsURLForPhone({ isForNewDevice = false, } = {}) {
|
|
1340
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1341
|
-
const res = yield this.ctx.client.addSessionPublicKey(this.userId, {
|
|
1342
|
-
status: user_management_client_1.PublicKeyStatus.PENDING,
|
|
1343
|
-
type: user_management_client_1.PublicKeyType.WEB,
|
|
1344
|
-
});
|
|
1345
|
-
return this.getWebAuthURLForCreate({
|
|
1346
|
-
authType: 'phone',
|
|
1347
|
-
isForNewDevice,
|
|
1348
|
-
webAuthId: res.data.id,
|
|
1349
|
-
partnerId: res.data.partnerId,
|
|
1350
|
-
});
|
|
1351
|
-
});
|
|
1352
|
-
}
|
|
1353
|
-
/**
|
|
1354
|
-
* Returns a URL for setting up a new password.
|
|
1355
|
-
* @param {Object} opts the options object
|
|
1356
|
-
* @param {string} opts.authType - the auth type to use
|
|
1357
|
-
* @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
|
|
1358
|
-
* @param {Theme} [opts.theme] the portal theme to use in place of the partner's default
|
|
1359
|
-
* @returns {string} the URL
|
|
1360
|
-
*/
|
|
1361
|
-
getSetupPasswordURL({ authType = 'email', isForNewDevice = false, theme, } = {}) {
|
|
1362
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1363
|
-
const res = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
|
|
1364
|
-
status: user_management_client_1.PasswordStatus.PENDING,
|
|
1365
|
-
});
|
|
1366
|
-
return this.getPasswordURLForCreate({
|
|
1367
|
-
authType,
|
|
1368
|
-
isForNewDevice,
|
|
1369
|
-
passwordId: res.data.id,
|
|
1370
|
-
partnerId: res.data.partnerId,
|
|
1371
|
-
theme,
|
|
1372
|
-
});
|
|
1373
|
-
});
|
|
1374
|
-
}
|
|
1375
|
-
/**
|
|
1376
|
-
* Checks if the current session is active.
|
|
1377
|
-
* @returns `true` if active, `false` otherwise
|
|
1378
|
-
*/
|
|
1379
|
-
isSessionActive() {
|
|
1380
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1381
|
-
if (this.isUsingExternalWallet()) {
|
|
1382
|
-
return true;
|
|
1383
|
-
}
|
|
1384
|
-
const res = yield this.touchSession();
|
|
1385
|
-
return !!res.data.isAuthenticated;
|
|
1386
|
-
});
|
|
1387
|
-
}
|
|
1388
|
-
/**
|
|
1389
|
-
* Checks if a session is active and a wallet exists.
|
|
1390
|
-
* @returns `true` if active, `false` otherwise
|
|
1391
|
-
**/
|
|
1392
|
-
isFullyLoggedIn() {
|
|
1393
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1394
|
-
if (this.isUsingExternalWallet()) {
|
|
1395
|
-
return true;
|
|
1396
|
-
}
|
|
1397
|
-
const isSessionActive = yield this.isSessionActive();
|
|
1398
|
-
return (isSessionActive &&
|
|
1399
|
-
this.currentWalletIdsArray.length > 0 &&
|
|
1400
|
-
this.currentWalletIdsArray.reduce((acc, [id]) => acc && !!this.wallets[id], true));
|
|
1401
|
-
});
|
|
1402
|
-
}
|
|
1403
|
-
supportedAuthMethods(auth) {
|
|
1404
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1405
|
-
const { supportedAuthMethods } = yield this.ctx.client.getSupportedAuthMethods(auth);
|
|
1406
|
-
const authMethods = new Set();
|
|
1407
|
-
for (const type of supportedAuthMethods) {
|
|
1408
|
-
switch (type) {
|
|
1409
|
-
case 'PASSWORD':
|
|
1410
|
-
authMethods.add(user_management_client_1.AuthMethod.PASSWORD);
|
|
1411
|
-
break;
|
|
1412
|
-
case 'BIOMETRIC':
|
|
1413
|
-
authMethods.add(user_management_client_1.AuthMethod.PASSKEY);
|
|
1414
|
-
break;
|
|
1415
|
-
}
|
|
1416
|
-
}
|
|
1417
|
-
return authMethods;
|
|
1418
|
-
});
|
|
1419
|
-
}
|
|
1420
|
-
/**
|
|
1421
|
-
* Get hints associated with the users stored biometrics.
|
|
1422
|
-
* @returns Array containing useragents and AAGuids for stored biometrics
|
|
1423
|
-
*/
|
|
1424
|
-
getUserBiometricLocationHints() {
|
|
1425
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1426
|
-
if (!this.email && !this.phone && !this.farcasterUsername && !this.telegramUserId) {
|
|
1427
|
-
throw new Error('one of email, phone or farcaster username are required to get biometric location hints');
|
|
1428
|
-
}
|
|
1429
|
-
return yield this.ctx.client.getBiometricLocationHints({
|
|
1430
|
-
email: this.email,
|
|
1431
|
-
phone: this.phone,
|
|
1432
|
-
countryCode: this.countryCode,
|
|
1433
|
-
farcasterUsername: this.farcasterUsername,
|
|
1434
|
-
telegramUserId: this.telegramUserId,
|
|
1435
|
-
});
|
|
1436
|
-
});
|
|
1437
|
-
}
|
|
1438
|
-
setAuth(auth) {
|
|
1439
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1440
|
-
const authInfo = (0, user_management_client_1.extractAuthInfo)(auth);
|
|
1441
|
-
if (!authInfo) {
|
|
1442
|
-
return undefined;
|
|
1443
|
-
}
|
|
1444
|
-
switch (authInfo.authType) {
|
|
1445
|
-
case 'email':
|
|
1446
|
-
yield this.setEmail(authInfo.identifier);
|
|
1447
|
-
break;
|
|
1448
|
-
case 'phone':
|
|
1449
|
-
yield this.setPhoneNumber(authInfo.auth.phone, authInfo.auth.countryCode);
|
|
1450
|
-
break;
|
|
1451
|
-
case 'farcaster':
|
|
1452
|
-
yield this.setFarcasterUsername(authInfo.identifier);
|
|
1453
|
-
break;
|
|
1454
|
-
case 'telegram':
|
|
1455
|
-
yield this.setTelegramUserId(authInfo.identifier);
|
|
1456
|
-
break;
|
|
1457
|
-
}
|
|
1458
|
-
return authInfo;
|
|
1459
|
-
});
|
|
1460
|
-
}
|
|
1461
|
-
/**
|
|
1462
|
-
* Initiates a login.
|
|
1463
|
-
* @param {Object} opts the options object
|
|
1464
|
-
* @param {String} opts.email - the email to login with
|
|
1465
|
-
* @param {boolean} opts.useShortURL - whether to shorten the link
|
|
1466
|
-
* @returns - the WebAuth URL for logging in
|
|
1467
|
-
**/
|
|
1468
|
-
initiateUserLogin(_a) {
|
|
1469
|
-
var { useShortUrl = false } = _a, auth = __rest(_a, ["useShortUrl"]);
|
|
1470
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1471
|
-
const authInfo = yield this.setAuth(auth);
|
|
1472
|
-
if (!authInfo) {
|
|
1473
|
-
return;
|
|
1474
|
-
}
|
|
1475
|
-
const res = yield this.touchSession(true);
|
|
1476
|
-
if (!this.loginEncryptionKeyPair) {
|
|
1477
|
-
yield this.setLoginEncryptionKeyPair();
|
|
1478
|
-
}
|
|
1479
|
-
const webAuthLoginURL = yield this.getWebAuthURLForLogin({
|
|
1480
|
-
authType: authInfo.authType,
|
|
1481
|
-
sessionId: res.data.sessionId,
|
|
1482
|
-
partnerId: res.data.partnerId,
|
|
1483
|
-
loginEncryptionPublicKey: (0, utils_js_1.getPublicKeyHex)(this.loginEncryptionKeyPair),
|
|
1484
|
-
});
|
|
1485
|
-
if (!useShortUrl) {
|
|
1486
|
-
return webAuthLoginURL;
|
|
1487
|
-
}
|
|
1488
|
-
return this.shortenLoginLink(webAuthLoginURL);
|
|
1489
|
-
});
|
|
1490
|
-
}
|
|
1491
|
-
/**
|
|
1492
|
-
* Initiates a login.
|
|
1493
|
-
* @param email - the email to login with
|
|
1494
|
-
* @returns - a set of supported auth methods for the user
|
|
1495
|
-
**/
|
|
1496
|
-
initiateUserLoginV2(auth) {
|
|
1497
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1498
|
-
const authInfo = yield this.setAuth(auth);
|
|
1499
|
-
if (!authInfo) {
|
|
1500
|
-
return;
|
|
1501
|
-
}
|
|
1502
|
-
yield this.touchSession(true);
|
|
1503
|
-
if (!this.loginEncryptionKeyPair) {
|
|
1504
|
-
yield this.setLoginEncryptionKeyPair();
|
|
1505
|
-
}
|
|
1506
|
-
return yield this.supportedAuthMethods(authInfo.auth);
|
|
1507
|
-
});
|
|
1508
|
-
}
|
|
1509
|
-
/**
|
|
1510
|
-
* Initiates a login.
|
|
1511
|
-
* @param opts the options object
|
|
1512
|
-
* @param opts.phone the phone number
|
|
1513
|
-
* @param opts.countryCode the country code
|
|
1514
|
-
* @param opts.useShortURL - whether to shorten the link
|
|
1515
|
-
* @returns - the WebAuth URL for logging in
|
|
1516
|
-
**/
|
|
1517
|
-
initiateUserLoginForPhone(_a) {
|
|
1518
|
-
var { useShortUrl = false } = _a, auth = __rest(_a, ["useShortUrl"]);
|
|
1519
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1520
|
-
yield this.setAuth(auth);
|
|
1521
|
-
const res = yield this.touchSession(true);
|
|
1522
|
-
if (!this.loginEncryptionKeyPair) {
|
|
1523
|
-
yield this.setLoginEncryptionKeyPair();
|
|
1524
|
-
}
|
|
1525
|
-
const webAuthLoginURL = yield this.getWebAuthURLForLoginForPhone({
|
|
1526
|
-
sessionId: res.data.sessionId,
|
|
1527
|
-
loginEncryptionPublicKey: (0, utils_js_1.getPublicKeyHex)(this.loginEncryptionKeyPair),
|
|
1528
|
-
partnerId: res.data.partnerId,
|
|
1529
|
-
});
|
|
1530
|
-
if (!useShortUrl) {
|
|
1531
|
-
return webAuthLoginURL;
|
|
1532
|
-
}
|
|
1533
|
-
return this.shortenLoginLink(webAuthLoginURL);
|
|
1534
|
-
});
|
|
1535
|
-
}
|
|
1536
|
-
/**
|
|
1537
|
-
* Waits for the session to be active.
|
|
1538
|
-
**/
|
|
1539
|
-
waitForAccountCreation() {
|
|
1540
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1541
|
-
yield this.touchSession();
|
|
1542
|
-
// Remove external wallets if creating an account with Para
|
|
1543
|
-
this.currentExternalWalletAddresses = undefined;
|
|
1544
|
-
this.externalWallets = {};
|
|
1545
|
-
this.isAwaitingAccountCreation = true;
|
|
1546
|
-
while (this.isAwaitingAccountCreation) {
|
|
1547
|
-
try {
|
|
1548
|
-
yield new Promise(resolve => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
|
|
1549
|
-
if (yield this.isSessionActive()) {
|
|
1550
|
-
this.isAwaitingAccountCreation = false;
|
|
1551
|
-
(0, index_js_2.dispatchEvent)(index_js_1.ParaEvent.ACCOUNT_CREATION_EVENT, true);
|
|
1552
|
-
return true;
|
|
1553
|
-
}
|
|
1554
|
-
}
|
|
1555
|
-
catch (err) {
|
|
1556
|
-
// want to continue polling on error
|
|
1557
|
-
console.error(err);
|
|
1558
|
-
}
|
|
1559
|
-
}
|
|
1560
|
-
return false;
|
|
1561
|
-
});
|
|
1562
|
-
}
|
|
1563
|
-
waitForPasskeyAndCreateWallet() {
|
|
1564
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1565
|
-
yield this.waitForAccountCreation();
|
|
1566
|
-
const pregenWallets = yield this.getPregenWallets();
|
|
1567
|
-
let recoverySecret, walletIds = {};
|
|
1568
|
-
if (pregenWallets.length > 0) {
|
|
1569
|
-
recoverySecret = yield this.claimPregenWallets();
|
|
1570
|
-
walletIds = this.supportedWalletTypes.reduce((acc, { type }) => {
|
|
1571
|
-
var _a;
|
|
1572
|
-
return Object.assign(Object.assign({}, acc), { [type]: [(_a = pregenWallets.find(w => !!index_js_2.WalletSchemeTypeMap[w.scheme][type])) === null || _a === void 0 ? void 0 : _a.id] });
|
|
1573
|
-
}, {});
|
|
1574
|
-
}
|
|
1575
|
-
// After claiming any pregen wallets, create wallets for the remaining missing types
|
|
1576
|
-
const created = yield this.createWalletPerType();
|
|
1577
|
-
recoverySecret = recoverySecret !== null && recoverySecret !== void 0 ? recoverySecret : created.recoverySecret;
|
|
1578
|
-
walletIds = Object.assign(Object.assign({}, walletIds), created.walletIds);
|
|
1579
|
-
const resp = { walletIds, recoverySecret };
|
|
1580
|
-
(0, index_js_2.dispatchEvent)(index_js_1.ParaEvent.ACCOUNT_SETUP_EVENT, resp);
|
|
1581
|
-
return resp;
|
|
1582
|
-
});
|
|
1583
|
-
}
|
|
1584
|
-
/**
|
|
1585
|
-
* Initiates a Farcaster login attempt and return the URI for the user to connect.
|
|
1586
|
-
* You can create a QR code with this URI that works with Farcaster's mobile app.
|
|
1587
|
-
* @return {string} the Farcaster connect URI
|
|
1588
|
-
*/
|
|
1589
|
-
getFarcasterConnectURL() {
|
|
1590
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1591
|
-
yield this.logout();
|
|
1592
|
-
yield this.touchSession(true);
|
|
1593
|
-
const { data: { connect_uri }, } = yield this.ctx.client.initializeFarcasterLogin();
|
|
1594
|
-
return connect_uri;
|
|
1595
|
-
});
|
|
1596
|
-
}
|
|
1597
|
-
/**
|
|
1598
|
-
* Awaits the response from a user's attempt to log in with Farcaster.
|
|
1599
|
-
* If successful, this returns the user's Farcaster username and profile picture and indicates whether the user already exists.
|
|
1600
|
-
* @return {Object} `{userExists: boolean; username: string; pfpUrl?: string | null }` - the user's information and whether the user already exists.
|
|
1601
|
-
*/
|
|
1602
|
-
waitForFarcasterStatus() {
|
|
1603
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1604
|
-
this.isAwaitingFarcaster = true;
|
|
1605
|
-
while (this.isAwaitingFarcaster) {
|
|
1606
|
-
try {
|
|
1607
|
-
yield new Promise(resolve => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
|
|
1608
|
-
const res = yield this.ctx.client.getFarcasterAuthStatus();
|
|
1609
|
-
if (res.data.state === 'completed') {
|
|
1610
|
-
const { userId, userExists, username, pfpUrl } = res.data;
|
|
1611
|
-
yield this.setUserId(userId);
|
|
1612
|
-
yield this.setFarcasterUsername(username);
|
|
1613
|
-
return {
|
|
1614
|
-
userExists,
|
|
1615
|
-
username,
|
|
1616
|
-
pfpUrl,
|
|
1617
|
-
};
|
|
1618
|
-
}
|
|
1619
|
-
}
|
|
1620
|
-
catch (err) {
|
|
1621
|
-
console.error(err);
|
|
1622
|
-
this.isAwaitingFarcaster = false;
|
|
1623
|
-
}
|
|
1624
|
-
}
|
|
1625
|
-
});
|
|
1626
|
-
}
|
|
1627
|
-
/**
|
|
1628
|
-
* Generates a URL for the user to log in with OAuth using a desire method.
|
|
1629
|
-
*
|
|
1630
|
-
* @param {Object} opts the options object
|
|
1631
|
-
* @param {OAuthMethod} opts.method the third-party service to use for OAuth.
|
|
1632
|
-
* @returns {string} the URL for the user to log in with OAuth.
|
|
1633
|
-
*/
|
|
1634
|
-
getOAuthURL({ method }) {
|
|
1635
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1636
|
-
yield this.logout();
|
|
1637
|
-
const res = yield this.touchSession(true);
|
|
1638
|
-
return (0, index_js_2.constructUrl)({
|
|
1639
|
-
base: method === user_management_client_1.OAuthMethod.TELEGRAM ? (0, index_js_2.getPortalBaseURL)(this.ctx, true) : (0, userManagementClient_js_1.getBaseOAuthUrl)(this.ctx.env),
|
|
1640
|
-
path: `/auth/${method.toLowerCase()}`,
|
|
1641
|
-
params: {
|
|
1642
|
-
apiKey: this.ctx.apiKey,
|
|
1643
|
-
sessionLookupId: res.data.sessionLookupId,
|
|
1644
|
-
},
|
|
1645
|
-
});
|
|
1646
|
-
});
|
|
1647
|
-
}
|
|
1648
|
-
/**
|
|
1649
|
-
* Awaits the response from a user's attempt to log in with OAuth.
|
|
1650
|
-
* If successful, this returns the user's email address and indicates whether the user already exists.
|
|
1651
|
-
*
|
|
1652
|
-
* @param {Object} opts the options object.
|
|
1653
|
-
* @param {Window} [opts.popupWindow] the popup window being used for login.
|
|
1654
|
-
* @return {Object} `{ email?: string; isError?: boolean; userExists: boolean; }` the result data
|
|
1655
|
-
*/
|
|
1656
|
-
waitForOAuth({ popupWindow } = {}) {
|
|
1657
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1658
|
-
this.isAwaitingOAuth = true;
|
|
1659
|
-
while (this.isAwaitingOAuth) {
|
|
1660
|
-
try {
|
|
1661
|
-
if (popupWindow === null || popupWindow === void 0 ? void 0 : popupWindow.closed) {
|
|
1662
|
-
return { isError: true, userExists: false };
|
|
1663
|
-
}
|
|
1664
|
-
yield new Promise(resolve => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
|
|
1665
|
-
if (this.isAwaitingOAuth) {
|
|
1666
|
-
const res = yield this.touchSession();
|
|
1667
|
-
if (res.data.userId) {
|
|
1668
|
-
const { userId, email } = res.data;
|
|
1669
|
-
yield this.setUserId(userId);
|
|
1670
|
-
yield this.setEmail(email);
|
|
1671
|
-
const userExists = yield this.checkIfUserExists({ email });
|
|
1672
|
-
this.isAwaitingOAuth = false;
|
|
1673
|
-
return {
|
|
1674
|
-
userExists,
|
|
1675
|
-
email,
|
|
1676
|
-
};
|
|
1677
|
-
}
|
|
1678
|
-
}
|
|
1679
|
-
}
|
|
1680
|
-
catch (err) {
|
|
1681
|
-
console.error(err);
|
|
1682
|
-
}
|
|
1683
|
-
}
|
|
1684
|
-
return { userExists: false };
|
|
1685
|
-
});
|
|
1686
|
-
}
|
|
1687
|
-
/**
|
|
1688
|
-
* Waits for the session to be active and sets up the user.
|
|
1689
|
-
*
|
|
1690
|
-
* @param {Object} opts the options object
|
|
1691
|
-
* @param {Window} [opts.popupWindow] the popup window being used for login.
|
|
1692
|
-
* @param {boolean} [opts.skipSessionRefresh] whether to skip refreshing the session.
|
|
1693
|
-
* @returns {Object} `{ isComplete: boolean; isError: boolean; needsWallet: boolean; partnerId: string; }` the result data
|
|
1694
|
-
**/
|
|
1695
|
-
waitForLoginAndSetup({ popupWindow, skipSessionRefresh = false, } = {}) {
|
|
1696
|
-
var _a;
|
|
1697
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1698
|
-
// Remove external wallets if logging in with Capsule
|
|
1699
|
-
this.currentExternalWalletAddresses = undefined;
|
|
1700
|
-
this.externalWallets = {};
|
|
1701
|
-
this.isAwaitingLogin = true;
|
|
1702
|
-
while (this.isAwaitingLogin) {
|
|
1703
|
-
try {
|
|
1704
|
-
yield new Promise(resolve => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
|
|
1705
|
-
if (!(yield this.isSessionActive())) {
|
|
1706
|
-
if (popupWindow === null || popupWindow === void 0 ? void 0 : popupWindow.closed) {
|
|
1707
|
-
const resp = { isComplete: false, isError: true };
|
|
1708
|
-
(0, index_js_2.dispatchEvent)(index_js_1.ParaEvent.LOGIN_EVENT, resp, 'failed to setup user');
|
|
1709
|
-
return resp;
|
|
1710
|
-
}
|
|
1711
|
-
continue;
|
|
1712
|
-
}
|
|
1713
|
-
const postLoginData = yield this.userSetupAfterLogin();
|
|
1714
|
-
const needsWallet = (_a = postLoginData.data.needsWallet) !== null && _a !== void 0 ? _a : false;
|
|
1715
|
-
if (!needsWallet) {
|
|
1716
|
-
if (this.currentWalletIdsArray.length === 0) {
|
|
1717
|
-
if (popupWindow === null || popupWindow === void 0 ? void 0 : popupWindow.closed) {
|
|
1718
|
-
const resp = { isComplete: false, isError: true };
|
|
1719
|
-
(0, index_js_2.dispatchEvent)(index_js_1.ParaEvent.LOGIN_EVENT, resp, 'failed to setup user');
|
|
1720
|
-
return resp;
|
|
1721
|
-
}
|
|
1722
|
-
else {
|
|
1723
|
-
continue;
|
|
1724
|
-
}
|
|
1725
|
-
}
|
|
1726
|
-
}
|
|
1727
|
-
const fetchedWallets = yield this.fetchWallets();
|
|
1728
|
-
const tempSharesRes = yield this.getTransmissionKeyShares();
|
|
1729
|
-
// need this check for the case where user has logged in but temp encrypted shares
|
|
1730
|
-
// haven't been sent to the backend yet
|
|
1731
|
-
if (tempSharesRes.data.temporaryShares.length === fetchedWallets.length) {
|
|
1732
|
-
yield this.setupAfterLogin({ temporaryShares: tempSharesRes.data.temporaryShares, skipSessionRefresh });
|
|
1733
|
-
yield this.claimPregenWallets();
|
|
1734
|
-
const resp = {
|
|
1735
|
-
isComplete: true,
|
|
1736
|
-
needsWallet: needsWallet || Object.values(this.wallets).length === 0,
|
|
1737
|
-
partnerId: postLoginData.data.partnerId,
|
|
1738
|
-
};
|
|
1739
|
-
(0, index_js_2.dispatchEvent)(index_js_1.ParaEvent.LOGIN_EVENT, resp);
|
|
1740
|
-
return resp;
|
|
1741
|
-
}
|
|
1742
|
-
}
|
|
1743
|
-
catch (err) {
|
|
1744
|
-
// want to continue polling on error
|
|
1745
|
-
console.error(err);
|
|
1746
|
-
}
|
|
1747
|
-
}
|
|
1748
|
-
const resp = { isComplete: false };
|
|
1749
|
-
(0, index_js_2.dispatchEvent)(index_js_1.ParaEvent.LOGIN_EVENT, resp, 'exitted login without setting up user');
|
|
1750
|
-
return resp;
|
|
1751
|
-
});
|
|
1752
|
-
}
|
|
1753
|
-
/**
|
|
1754
|
-
* Updates the session with the user management server, possibly
|
|
1755
|
-
* opening a popup to refresh the session.
|
|
1756
|
-
*
|
|
1757
|
-
* @param {Object} opts the options object.
|
|
1758
|
-
* @param {boolean} [shouldOpenPopup] - if `true`, the running device will open a popup to reauthenticate the user.
|
|
1759
|
-
* @returns a URL for the user to reauthenticate.
|
|
1760
|
-
**/
|
|
1761
|
-
refreshSession({ shouldOpenPopup = false } = {}) {
|
|
1762
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1763
|
-
const res = yield this.touchSession(true);
|
|
1764
|
-
if (!this.loginEncryptionKeyPair) {
|
|
1765
|
-
yield this.setLoginEncryptionKeyPair();
|
|
1766
|
-
}
|
|
1767
|
-
const link = yield this.getWebAuthURLForLogin({
|
|
1768
|
-
sessionId: res.data.sessionId,
|
|
1769
|
-
loginEncryptionPublicKey: (0, utils_js_1.getPublicKeyHex)(this.loginEncryptionKeyPair),
|
|
1770
|
-
});
|
|
1771
|
-
if (shouldOpenPopup) {
|
|
1772
|
-
this.platformUtils.openPopup(link);
|
|
1773
|
-
}
|
|
1774
|
-
return link;
|
|
1775
|
-
});
|
|
1776
|
-
}
|
|
1777
|
-
/**
|
|
1778
|
-
* Call this method after login to ensure that the user ID is set
|
|
1779
|
-
* internally.
|
|
1780
|
-
**/
|
|
1781
|
-
userSetupAfterLogin() {
|
|
1782
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1783
|
-
const res = yield this.touchSession();
|
|
1784
|
-
yield this.setUserId(res.data.userId);
|
|
1785
|
-
if (res.data.currentWalletIds && res.data.currentWalletIds !== this.currentWalletIds)
|
|
1786
|
-
yield this.setCurrentWalletIds(res.data.currentWalletIds, {
|
|
1787
|
-
sessionLookupId: this.isPortal() ? res.data.sessionLookupId : undefined,
|
|
1788
|
-
});
|
|
1789
|
-
return res;
|
|
1790
|
-
});
|
|
1791
|
-
}
|
|
1792
|
-
/**
|
|
1793
|
-
* Get transmission shares associated with session.
|
|
1794
|
-
* @param {Object} opts the options object.
|
|
1795
|
-
* @param {boolean} opts.isForNewDevice - true if this device is registering.
|
|
1796
|
-
* @returns - transmission keyshares.
|
|
1797
|
-
**/
|
|
1798
|
-
getTransmissionKeyShares({ isForNewDevice = false } = {}) {
|
|
1799
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1800
|
-
const res = yield this.touchSession();
|
|
1801
|
-
const sessionLookupId = isForNewDevice ? `${res.data.sessionLookupId}-new-device` : res.data.sessionLookupId;
|
|
1802
|
-
return this.ctx.client.getTransmissionKeyshares(this.userId, sessionLookupId);
|
|
1803
|
-
});
|
|
1804
|
-
}
|
|
1805
|
-
/**
|
|
1806
|
-
* Call this method after login to perform setup.
|
|
1807
|
-
* @param {Object} opts the options object.
|
|
1808
|
-
* @param {any[]} opts.temporaryShares optional temporary shares to use for decryption.
|
|
1809
|
-
* @param {boolean} [opts.skipSessionRefresh] - whether or not to skip refreshing the session.
|
|
1810
|
-
**/
|
|
1811
|
-
setupAfterLogin({ temporaryShares, skipSessionRefresh = false, } = {}) {
|
|
1812
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1813
|
-
if (!temporaryShares) {
|
|
1814
|
-
temporaryShares = (yield this.getTransmissionKeyShares()).data.temporaryShares;
|
|
1815
|
-
}
|
|
1816
|
-
temporaryShares.forEach(share => {
|
|
1817
|
-
const signer = (0, utils_js_1.decryptWithPrivateKey)(this.loginEncryptionKeyPair.privateKey, share.encryptedShare, share.encryptedKey);
|
|
1818
|
-
this.wallets[share.walletId] = {
|
|
1819
|
-
id: share.walletId,
|
|
1820
|
-
signer,
|
|
1821
|
-
};
|
|
1822
|
-
});
|
|
1823
|
-
yield this.deleteLoginEncryptionKeyPair();
|
|
1824
|
-
yield this.populateWalletAddresses();
|
|
1825
|
-
yield this.touchSession(!skipSessionRefresh);
|
|
1826
|
-
});
|
|
1827
|
-
}
|
|
1828
|
-
/**
|
|
1829
|
-
* Distributes a new wallet recovery share.
|
|
1830
|
-
* @param {Object} opts the options object.
|
|
1831
|
-
* @param {string} opts.walletId the wallet to distribute the recovery share for.
|
|
1832
|
-
* @param {string} opts.userShare optional user share generate the recovery share from. Defaults to the signer from the passed in walletId
|
|
1833
|
-
* @param {boolean} opts.skipBiometricShareCreation whether or not to skip biometric share creation. Used when regenerating recovery shares.
|
|
1834
|
-
* @param {boolean} opts.forceRefreshRecovery whether or not to force recovery secret regeneration. Used when regenerating recovery shares.
|
|
1835
|
-
* @returns {string} the recovery share.
|
|
1836
|
-
**/
|
|
1837
|
-
distributeNewWalletShare({ walletId, userShare, skipBiometricShareCreation = false, forceRefresh = false, }) {
|
|
1838
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1839
|
-
let userSigner = userShare;
|
|
1840
|
-
if (!userSigner) {
|
|
1841
|
-
userSigner = this.wallets[walletId].signer;
|
|
1842
|
-
}
|
|
1843
|
-
const recoveryShare = skipBiometricShareCreation
|
|
1844
|
-
? yield (0, recovery_js_1.sendRecoveryForShare)({
|
|
1845
|
-
ctx: this.ctx,
|
|
1846
|
-
userId: this.userId,
|
|
1847
|
-
walletId,
|
|
1848
|
-
userSigner,
|
|
1849
|
-
emailProps: this.getBackupKitEmailProps(),
|
|
1850
|
-
forceRefresh,
|
|
1851
|
-
})
|
|
1852
|
-
: yield (0, shareDistribution_js_1.distributeNewShare)({
|
|
1853
|
-
ctx: this.ctx,
|
|
1854
|
-
userId: this.userId,
|
|
1855
|
-
walletId,
|
|
1856
|
-
userShare: userSigner,
|
|
1857
|
-
emailProps: this.getBackupKitEmailProps(),
|
|
1858
|
-
});
|
|
1859
|
-
return recoveryShare;
|
|
1860
|
-
});
|
|
1861
|
-
}
|
|
1862
|
-
waitForWalletAddress(walletId) {
|
|
1863
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1864
|
-
let maxPolls = 0;
|
|
1865
|
-
while (true) {
|
|
1866
|
-
try {
|
|
1867
|
-
if (maxPolls === 10) {
|
|
1868
|
-
break;
|
|
1869
|
-
}
|
|
1870
|
-
++maxPolls;
|
|
1871
|
-
const res = yield this.ctx.client.getWallets(this.userId);
|
|
1872
|
-
const wallet = res.data.wallets.find(w => w.id === walletId);
|
|
1873
|
-
if (wallet && wallet.address) {
|
|
1874
|
-
return;
|
|
1875
|
-
}
|
|
1876
|
-
yield new Promise(resolve => setTimeout(resolve, constants.SHORT_POLLING_INTERVAL_MS));
|
|
1877
|
-
}
|
|
1878
|
-
catch (err) {
|
|
1879
|
-
// want to continue polling on error
|
|
1880
|
-
console.error(err);
|
|
1881
|
-
}
|
|
1882
|
-
}
|
|
1883
|
-
throw new Error('timed out waiting for wallet address');
|
|
1884
|
-
});
|
|
1885
|
-
}
|
|
1886
|
-
/**
|
|
1887
|
-
* Waits for a pregen wallet address to be created.
|
|
1888
|
-
*
|
|
1889
|
-
* @param pregenIdentifier - the identifier of the user the pregen wallet is associated with.
|
|
1890
|
-
* @param walletId - the wallet id
|
|
1891
|
-
* @param pregenIdentifierType - the identifier type of the user the pregen wallet is associated with.
|
|
1892
|
-
* @returns - recovery share.
|
|
1893
|
-
**/
|
|
1894
|
-
waitForPregenWalletAddress(walletId) {
|
|
1895
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1896
|
-
let maxPolls = 0;
|
|
1897
|
-
while (true) {
|
|
1898
|
-
try {
|
|
1899
|
-
if (maxPolls === 10) {
|
|
1900
|
-
break;
|
|
1901
|
-
}
|
|
1902
|
-
++maxPolls;
|
|
1903
|
-
const res = yield this.getPregenWallets();
|
|
1904
|
-
const wallet = res.find(w => w.id === walletId);
|
|
1905
|
-
if (wallet && wallet.address) {
|
|
1906
|
-
return;
|
|
1907
|
-
}
|
|
1908
|
-
yield new Promise(resolve => setTimeout(resolve, constants.SHORT_POLLING_INTERVAL_MS));
|
|
1909
|
-
}
|
|
1910
|
-
catch (err) {
|
|
1911
|
-
// want to continue polling on error
|
|
1912
|
-
console.error(err);
|
|
1913
|
-
}
|
|
1914
|
-
}
|
|
1915
|
-
throw new Error('timed out waiting for wallet address');
|
|
1916
|
-
});
|
|
1917
|
-
}
|
|
1918
|
-
/**
|
|
1919
|
-
* Creates several new wallets with the desired types. If no types are provided, this method
|
|
1920
|
-
* will create one for each of the non-optional types specified in the instance's `supportedWalletTypes`
|
|
1921
|
-
* object that are not already present. This is automatically called upon account creation to ensure that
|
|
1922
|
-
* the user has a wallet of each required type.
|
|
1923
|
-
*
|
|
1924
|
-
* @param {Object} [opts] the options object.
|
|
1925
|
-
* @param {boolean} [opts.skipDistribute] if `true`, the wallets' recovery share will not be distributed.
|
|
1926
|
-
* @param {WalletType[]} [opts.types] the types of wallets to create.
|
|
1927
|
-
* @returns {Object} the wallets created, their ids, and the recovery secret.
|
|
1928
|
-
**/
|
|
1929
|
-
createWalletPerType({ skipDistribute = false, types, } = {}) {
|
|
1930
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1931
|
-
const wallets = [];
|
|
1932
|
-
const walletIds = {};
|
|
1933
|
-
let recoverySecret;
|
|
1934
|
-
for (const type of yield this.getTypesToCreate(types)) {
|
|
1935
|
-
const [wallet, recoveryShare] = yield this.createWallet({ type, skipDistribute });
|
|
1936
|
-
wallets.push(wallet);
|
|
1937
|
-
(0, index_js_2.getEquivalentTypes)(type)
|
|
1938
|
-
.filter(t => !!this.isWalletTypeEnabled[t])
|
|
1939
|
-
.forEach(t => {
|
|
1940
|
-
walletIds[t] = [wallet.id];
|
|
1941
|
-
});
|
|
1942
|
-
if (recoveryShare) {
|
|
1943
|
-
recoverySecret = recoveryShare;
|
|
1944
|
-
}
|
|
1945
|
-
}
|
|
1946
|
-
return { wallets, walletIds, recoverySecret };
|
|
1947
|
-
});
|
|
1948
|
-
}
|
|
1949
|
-
/**
|
|
1950
|
-
* Refresh the current user share for a wallet.
|
|
1951
|
-
*
|
|
1952
|
-
* @param {Object} opts the options object.
|
|
1953
|
-
* @param {string} opts.walletId the wallet id to refresh.
|
|
1954
|
-
* @param {string} opts.share the current user share.
|
|
1955
|
-
* @param {string} [opts.oldPartnerId] the current partner id.
|
|
1956
|
-
* @param {string} [opts.newPartnerId] the new partner id to set, if any.
|
|
1957
|
-
* @param {string} [opts.keyShareProtocolId]
|
|
1958
|
-
* @param {boolean} [opts.redistributeBackupEncryptedShares] whether or not to redistribute backup encrypted shares.
|
|
1959
|
-
* @returns {Object} the new user share and recovery secret.
|
|
1960
|
-
**/
|
|
1961
|
-
refreshShare({ walletId, share, oldPartnerId, newPartnerId, keyShareProtocolId, redistributeBackupEncryptedShares, }) {
|
|
1962
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1963
|
-
const { signer, protocolId } = yield this.platformUtils.refresh(this.ctx, this.retrieveSessionCookie(), this.userId, walletId, share, oldPartnerId, newPartnerId, keyShareProtocolId);
|
|
1964
|
-
const recoverySecret = yield (0, shareDistribution_js_1.distributeNewShare)({
|
|
1965
|
-
ctx: this.ctx,
|
|
1966
|
-
userId: this.userId,
|
|
1967
|
-
walletId,
|
|
1968
|
-
userShare: signer,
|
|
1969
|
-
ignoreRedistributingBackupEncryptedShare: !redistributeBackupEncryptedShares,
|
|
1970
|
-
emailProps: this.getBackupKitEmailProps(),
|
|
1971
|
-
partnerId: newPartnerId,
|
|
1972
|
-
protocolId,
|
|
1973
|
-
});
|
|
1974
|
-
return { signer, recoverySecret, protocolId };
|
|
1975
|
-
});
|
|
1976
|
-
}
|
|
1977
|
-
/**
|
|
1978
|
-
* Creates a new wallet.
|
|
1979
|
-
* @param {Object} opts the options object.
|
|
1980
|
-
* @param {WalletType} opts.type the type of wallet to create.
|
|
1981
|
-
* @param {boolean} opts.skipDistribute - if true, recovery share will not be distributed.
|
|
1982
|
-
* @returns {[Wallet, string | null]} `[wallet, recoveryShare]` - the wallet object and the new recovery share.
|
|
1983
|
-
**/
|
|
1984
|
-
createWallet({ type: _type, skipDistribute = false, } = {}) {
|
|
1985
|
-
var _a, _b;
|
|
1986
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1987
|
-
this.requireApiKey();
|
|
1988
|
-
const walletType = yield this.assertIsValidWalletType(_type !== null && _type !== void 0 ? _type : (_a = this.supportedWalletTypes.find(({ optional }) => !optional)) === null || _a === void 0 ? void 0 : _a.type);
|
|
1989
|
-
let signer;
|
|
1990
|
-
let wallet;
|
|
1991
|
-
let keygenRes;
|
|
1992
|
-
switch (walletType) {
|
|
1993
|
-
case user_management_client_1.WalletType.SOLANA: {
|
|
1994
|
-
keygenRes = yield this.platformUtils.ed25519Keygen(this.ctx, this.userId, this.retrieveSessionCookie(), this.getBackupKitEmailProps());
|
|
1995
|
-
break;
|
|
1996
|
-
}
|
|
1997
|
-
default: {
|
|
1998
|
-
keygenRes = yield this.platformUtils.keygen(this.ctx, this.userId, walletType, null, this.retrieveSessionCookie(), this.getBackupKitEmailProps());
|
|
1999
|
-
break;
|
|
2000
|
-
}
|
|
2001
|
-
}
|
|
2002
|
-
const walletId = keygenRes.walletId;
|
|
2003
|
-
signer = keygenRes.signer;
|
|
2004
|
-
this.wallets[walletId] = {
|
|
2005
|
-
id: walletId,
|
|
2006
|
-
signer,
|
|
2007
|
-
scheme: walletType === user_management_client_1.WalletType.SOLANA ? user_management_client_1.WalletScheme.ED25519 : user_management_client_1.WalletScheme.DKLS,
|
|
2008
|
-
type: walletType,
|
|
2009
|
-
};
|
|
2010
|
-
wallet = this.wallets[walletId];
|
|
2011
|
-
yield this.waitForWalletAddress(wallet.id);
|
|
2012
|
-
yield this.populateWalletAddresses();
|
|
2013
|
-
let recoveryShare = null;
|
|
2014
|
-
if (!skipDistribute) {
|
|
2015
|
-
recoveryShare = yield (0, shareDistribution_js_1.distributeNewShare)({
|
|
2016
|
-
ctx: this.ctx,
|
|
2017
|
-
userId: this.userId,
|
|
2018
|
-
walletId: wallet.id,
|
|
2019
|
-
userShare: signer,
|
|
2020
|
-
emailProps: this.getBackupKitEmailProps(),
|
|
2021
|
-
});
|
|
2022
|
-
}
|
|
2023
|
-
yield this.setCurrentWalletIds(Object.assign(Object.assign({}, this.currentWalletIds), { [walletType]: [...((_b = this.currentWalletIds[walletType]) !== null && _b !== void 0 ? _b : []), walletId] }));
|
|
2024
|
-
const walletNoSigner = Object.assign({}, wallet);
|
|
2025
|
-
delete walletNoSigner.signer;
|
|
2026
|
-
(0, index_js_2.dispatchEvent)(index_js_1.ParaEvent.WALLET_CREATED, {
|
|
2027
|
-
wallet: walletNoSigner,
|
|
2028
|
-
recoverySecret: recoveryShare,
|
|
2029
|
-
});
|
|
2030
|
-
return [wallet, recoveryShare];
|
|
2031
|
-
});
|
|
2032
|
-
}
|
|
2033
|
-
/**
|
|
2034
|
-
* Creates a new pregenerated wallet.
|
|
2035
|
-
*
|
|
2036
|
-
* @param {Object} opts the options object.
|
|
2037
|
-
* @param {string} opts.pregenIdentifier the identifier associated with the new wallet.
|
|
2038
|
-
* @param {TPregenIdentifierType} [opts.pregenIdentifierType] the identifier type. Defaults to `EMAIL`.
|
|
2039
|
-
* @param {WalletType} [opts.type] the type of wallet to create. Defaults to the first non-optional type in the instance's `supportedWalletTypes` array.
|
|
2040
|
-
* @returns {Wallet} the created wallet.
|
|
2041
|
-
**/
|
|
2042
|
-
createPregenWallet(opts) {
|
|
2043
|
-
var _a, _b;
|
|
2044
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2045
|
-
const { type: _type = (_a = this.supportedWalletTypes.find(({ optional }) => !optional)) === null || _a === void 0 ? void 0 : _a.type, pregenIdentifier, pregenIdentifierType = 'EMAIL', } = opts;
|
|
2046
|
-
this.requireApiKey();
|
|
2047
|
-
const walletType = yield this.assertIsValidWalletType(_type !== null && _type !== void 0 ? _type : (_b = this.supportedWalletTypes.find(({ optional }) => !optional)) === null || _b === void 0 ? void 0 : _b.type);
|
|
2048
|
-
let keygenRes;
|
|
2049
|
-
switch (walletType) {
|
|
2050
|
-
case user_management_client_1.WalletType.SOLANA:
|
|
2051
|
-
keygenRes = yield this.platformUtils.ed25519PreKeygen(this.ctx, pregenIdentifier, pregenIdentifierType, this.retrieveSessionCookie());
|
|
2052
|
-
break;
|
|
2053
|
-
default:
|
|
2054
|
-
keygenRes = yield this.platformUtils.preKeygen(this.ctx, undefined, pregenIdentifier, pregenIdentifierType, walletType, null, this.retrieveSessionCookie());
|
|
2055
|
-
break;
|
|
2056
|
-
}
|
|
2057
|
-
const { signer, walletId } = keygenRes;
|
|
2058
|
-
this.wallets[walletId] = {
|
|
2059
|
-
id: walletId,
|
|
2060
|
-
signer,
|
|
2061
|
-
scheme: walletType === user_management_client_1.WalletType.SOLANA ? user_management_client_1.WalletScheme.ED25519 : user_management_client_1.WalletScheme.DKLS,
|
|
2062
|
-
type: walletType,
|
|
2063
|
-
isPregen: true,
|
|
2064
|
-
pregenIdentifier,
|
|
2065
|
-
pregenIdentifierType,
|
|
2066
|
-
};
|
|
2067
|
-
yield this.waitForPregenWalletAddress(walletId);
|
|
2068
|
-
yield this.populatePregenWalletAddresses();
|
|
2069
|
-
return this.wallets[walletId];
|
|
2070
|
-
});
|
|
2071
|
-
}
|
|
2072
|
-
/**
|
|
2073
|
-
* Creates new pregenerated wallets for each desired type.
|
|
2074
|
-
* If no types are provided, this method will create one for each of the non-optional types
|
|
2075
|
-
* specified in the instance's `supportedWalletTypes` array that are not already present.
|
|
2076
|
-
* @param {Object} opts the options object.
|
|
2077
|
-
* @param {string} opts.pregenIdentifier the identifier to associate each wallet with.
|
|
2078
|
-
* @param {TPregenIdentifierType} opts.pregenIdentifierType - either `'EMAIL'` or `'PHONE'`.
|
|
2079
|
-
* @param {WalletType[]} [opts.types] the wallet types to create. Defaults to any types the instance supports that are not already present.
|
|
2080
|
-
* @returns {Wallet[]} an array containing the created wallets.
|
|
2081
|
-
**/
|
|
2082
|
-
createPregenWalletPerType({ types, pregenIdentifier, pregenIdentifierType = 'EMAIL', }) {
|
|
2083
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2084
|
-
const wallets = [];
|
|
2085
|
-
for (const type of yield this.getTypesToCreate(types)) {
|
|
2086
|
-
const wallet = yield this.createPregenWallet({ type, pregenIdentifier, pregenIdentifierType });
|
|
2087
|
-
wallets.push(wallet);
|
|
2088
|
-
}
|
|
2089
|
-
return wallets;
|
|
2090
|
-
});
|
|
2091
|
-
}
|
|
2092
|
-
/**
|
|
2093
|
-
* Claims a pregenerated wallet.
|
|
2094
|
-
*
|
|
2095
|
-
* @param {Object} opts the options object.
|
|
2096
|
-
* @param {string} opts.pregenIdentifier string the identifier of the user claiming the wallet
|
|
2097
|
-
* @param {TPregenIdentifierType} opts.pregenIdentifierType type of the identifier of the user claiming the wallet
|
|
2098
|
-
* @returns {[Wallet, string | null]} `[wallet, recoveryShare]` - the wallet object and the new recovery share.
|
|
2099
|
-
**/
|
|
2100
|
-
claimPregenWallets({ pregenIdentifier, pregenIdentifierType = !!pregenIdentifier ? 'EMAIL' : undefined, } = {}) {
|
|
2101
|
-
var _a;
|
|
2102
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2103
|
-
this.requireApiKey();
|
|
2104
|
-
const pregenWallets = pregenIdentifier && pregenIdentifierType
|
|
2105
|
-
? yield this.getPregenWallets({ pregenIdentifier, pregenIdentifierType })
|
|
2106
|
-
: yield this.getPregenWallets();
|
|
2107
|
-
if (pregenWallets.length === 0) {
|
|
2108
|
-
return undefined;
|
|
2109
|
-
}
|
|
2110
|
-
let newRecoverySecret;
|
|
2111
|
-
const { walletIds } = yield this.ctx.client.claimPregenWallets({
|
|
2112
|
-
userId: this.userId,
|
|
2113
|
-
walletIds: pregenWallets.map(w => w.id),
|
|
2114
|
-
});
|
|
2115
|
-
for (const walletId of walletIds) {
|
|
2116
|
-
const wallet = this.wallets[walletId];
|
|
2117
|
-
let refreshedShare;
|
|
2118
|
-
if (wallet.scheme === user_management_client_1.WalletScheme.ED25519) {
|
|
2119
|
-
const distributeRes = yield (0, shareDistribution_js_1.distributeNewShare)({
|
|
2120
|
-
ctx: this.ctx,
|
|
2121
|
-
userId: this.userId,
|
|
2122
|
-
walletId: wallet.id,
|
|
2123
|
-
userShare: this.wallets[wallet.id].signer,
|
|
2124
|
-
emailProps: this.getBackupKitEmailProps(),
|
|
2125
|
-
partnerId: wallet.partnerId,
|
|
2126
|
-
});
|
|
2127
|
-
if (distributeRes.length > 0) {
|
|
2128
|
-
newRecoverySecret = distributeRes;
|
|
2129
|
-
}
|
|
2130
|
-
}
|
|
2131
|
-
else {
|
|
2132
|
-
refreshedShare = yield this.refreshShare({
|
|
2133
|
-
walletId: wallet.id,
|
|
2134
|
-
share: this.wallets[wallet.id].signer,
|
|
2135
|
-
oldPartnerId: wallet.partnerId,
|
|
2136
|
-
newPartnerId: wallet.partnerId,
|
|
2137
|
-
redistributeBackupEncryptedShares: true,
|
|
2138
|
-
});
|
|
2139
|
-
if (refreshedShare.recoverySecret) {
|
|
2140
|
-
newRecoverySecret = refreshedShare.recoverySecret;
|
|
2141
|
-
}
|
|
2142
|
-
}
|
|
2143
|
-
this.wallets[wallet.id] = Object.assign(Object.assign({}, this.wallets[wallet.id]), { signer: (_a = refreshedShare === null || refreshedShare === void 0 ? void 0 : refreshedShare.signer) !== null && _a !== void 0 ? _a : wallet.signer, userId: this.userId, pregenIdentifier: undefined, pregenIdentifierType: undefined });
|
|
2144
|
-
const walletNoSigner = Object.assign({}, this.wallets[wallet.id]);
|
|
2145
|
-
delete walletNoSigner.signer;
|
|
2146
|
-
(0, index_js_2.dispatchEvent)(index_js_1.ParaEvent.PREGEN_WALLET_CLAIMED, {
|
|
2147
|
-
wallet: walletNoSigner,
|
|
2148
|
-
recoverySecret: newRecoverySecret,
|
|
2149
|
-
});
|
|
2150
|
-
}
|
|
2151
|
-
yield this.setWallets(this.wallets);
|
|
2152
|
-
return newRecoverySecret;
|
|
2153
|
-
});
|
|
2154
|
-
}
|
|
2155
|
-
/**
|
|
2156
|
-
* Updates the identifier for a pregen wallet.
|
|
2157
|
-
* @param {Object} opts the options object.
|
|
2158
|
-
* @param {string} opts.walletId the pregen wallet ID
|
|
2159
|
-
* @param {string} opts.newPregenIdentifier the new identtifier
|
|
2160
|
-
* @param {TPregenIdentifierType} opts.newPregenIdentifierType: the new identifier type
|
|
2161
|
-
**/
|
|
2162
|
-
updatePregenWalletIdentifier({ walletId, newPregenIdentifier, newPregenIdentifierType, }) {
|
|
2163
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2164
|
-
this.requireApiKey();
|
|
2165
|
-
yield this.ctx.client.updatePregenWallet(walletId, {
|
|
2166
|
-
pregenIdentifier: newPregenIdentifier,
|
|
2167
|
-
pregenIdentifierType: newPregenIdentifierType,
|
|
2168
|
-
});
|
|
2169
|
-
if (!!this.wallets[walletId]) {
|
|
2170
|
-
this.wallets[walletId] = Object.assign(Object.assign({}, this.wallets[walletId]), { pregenIdentifier: newPregenIdentifier, pregenIdentifierType: newPregenIdentifierType });
|
|
2171
|
-
yield this.setWallets(this.wallets);
|
|
2172
|
-
}
|
|
2173
|
-
});
|
|
2174
|
-
}
|
|
2175
|
-
/**
|
|
2176
|
-
* Checks if a pregen Wallet exists for the given identifier with the current partner.
|
|
2177
|
-
* @param {Object} opts the options object.
|
|
2178
|
-
* @param {string} opts.pregenIdentifier string the identifier of the user claiming the wallet
|
|
2179
|
-
* @param {TPregenIdentifierType} opts.pregenIdentifierType type of the string of the identifier of the user claiming the wallet
|
|
2180
|
-
* @returns {boolean} whether the pregen wallet exists
|
|
2181
|
-
**/
|
|
2182
|
-
hasPregenWallet({ pregenIdentifier, pregenIdentifierType, }) {
|
|
2183
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2184
|
-
this.requireApiKey();
|
|
2185
|
-
// This function gets pregen wallets by identifier and partnerId
|
|
2186
|
-
const res = yield this.getPregenWallets({ pregenIdentifier, pregenIdentifierType });
|
|
2187
|
-
const wallet = res.find(w => w.pregenIdentifier === pregenIdentifier && w.pregenIdentifierType === pregenIdentifierType);
|
|
2188
|
-
if (!wallet) {
|
|
2189
|
-
return false;
|
|
2190
|
-
}
|
|
2191
|
-
return true;
|
|
2192
|
-
});
|
|
2193
|
-
}
|
|
2194
|
-
/**
|
|
2195
|
-
* Get pregen wallets for the given identifier.
|
|
2196
|
-
* @param {Object} opts the options object.
|
|
2197
|
-
* @param {string} opts.pregenIdentifier - the identifier of the user claiming the wallet
|
|
2198
|
-
* @param {TPregenIdentifierType} opts.pregenIdentifierType - type of the identifier of the user claiming the wallet
|
|
2199
|
-
* @returns {Promise<WalletEntity[]>} the array of found wallets
|
|
2200
|
-
**/
|
|
2201
|
-
getPregenWallets({ pregenIdentifier, pregenIdentifierType = !!pregenIdentifier ? 'EMAIL' : undefined, } = {}) {
|
|
2202
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2203
|
-
this.requireApiKey();
|
|
2204
|
-
const res = yield this.ctx.client.getPregenWallets(pregenIdentifier && pregenIdentifierType ? { [pregenIdentifierType]: [pregenIdentifier] } : this.pregenIds, this.isPortal(), this.userId);
|
|
2205
|
-
return res.wallets.filter(w => this.isWalletSupported((0, index_js_2.entityToWallet)(w)));
|
|
2206
|
-
});
|
|
2207
|
-
}
|
|
2208
|
-
encodeWalletBase64(wallet) {
|
|
2209
|
-
const walletJson = JSON.stringify(wallet);
|
|
2210
|
-
const base64Wallet = Buffer.from(walletJson).toString('base64');
|
|
2211
|
-
return base64Wallet;
|
|
2212
|
-
}
|
|
2213
|
-
/**
|
|
2214
|
-
* Encodes the current wallets encoded in Base 64.
|
|
2215
|
-
* @returns {string} the encoded wallet string
|
|
2216
|
-
**/
|
|
2217
|
-
getUserShare() {
|
|
2218
|
-
if (Object.values(this.wallets).length === 0) {
|
|
2219
|
-
return null;
|
|
2220
|
-
}
|
|
2221
|
-
return Object.values(this.wallets)
|
|
2222
|
-
.map(wallet => this.encodeWalletBase64(wallet))
|
|
2223
|
-
.join('-');
|
|
2224
|
-
}
|
|
2225
|
-
/**
|
|
2226
|
-
* Sets the current wallets from a Base 64 string.
|
|
2227
|
-
* @param {string} base64Wallet the encoded wallet string
|
|
2228
|
-
**/
|
|
2229
|
-
setUserShare(base64Wallets) {
|
|
2230
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2231
|
-
if (!base64Wallets) {
|
|
2232
|
-
return;
|
|
2233
|
-
}
|
|
2234
|
-
const base64WalletsSplit = base64Wallets.split('-');
|
|
2235
|
-
for (const base64Wallet of base64WalletsSplit) {
|
|
2236
|
-
const walletJson = Buffer.from(base64Wallet, 'base64').toString();
|
|
2237
|
-
const wallet = (0, index_js_2.migrateWallet)(JSON.parse(walletJson));
|
|
2238
|
-
this.wallets[wallet.id] = wallet;
|
|
2239
|
-
yield this.setWallets(this.wallets);
|
|
2240
|
-
}
|
|
2241
|
-
});
|
|
2242
|
-
}
|
|
2243
|
-
getTransactionReviewUrl(transactionId, timeoutMs) {
|
|
2244
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2245
|
-
const res = yield this.touchSession();
|
|
2246
|
-
return this.constructPortalUrl('txReview', {
|
|
2247
|
-
partnerId: res.data.partnerId,
|
|
2248
|
-
pathId: transactionId,
|
|
2249
|
-
params: {
|
|
2250
|
-
email: this.email,
|
|
2251
|
-
timeoutMs: timeoutMs === null || timeoutMs === void 0 ? void 0 : timeoutMs.toString(),
|
|
2252
|
-
},
|
|
2253
|
-
});
|
|
2254
|
-
});
|
|
2255
|
-
}
|
|
2256
|
-
getOnRampTransactionUrl(_a) {
|
|
2257
|
-
var { purchaseId, providerKey } = _a, walletParams = __rest(_a, ["purchaseId", "providerKey"]);
|
|
2258
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2259
|
-
const res = yield this.touchSession();
|
|
2260
|
-
const [key, identifier] = (0, user_management_client_1.extractWalletRef)(walletParams);
|
|
2261
|
-
return this.constructPortalUrl('onRamp', {
|
|
2262
|
-
partnerId: res.data.partnerId,
|
|
2263
|
-
pathId: purchaseId,
|
|
2264
|
-
sessionId: res.data.sessionId,
|
|
2265
|
-
params: {
|
|
2266
|
-
[key]: identifier,
|
|
2267
|
-
providerKey,
|
|
2268
|
-
currentWalletIds: JSON.stringify(this.currentWalletIds),
|
|
2269
|
-
},
|
|
2270
|
-
});
|
|
2271
|
-
});
|
|
2272
|
-
}
|
|
2273
|
-
/**
|
|
2274
|
-
* Signs a message using one of the current wallets.
|
|
2275
|
-
*
|
|
2276
|
-
* If you want to sign the keccak256 hash of a message, hash the
|
|
2277
|
-
* message first and then pass in the base64 encoded hash.
|
|
2278
|
-
* @param {Object} opts the options object.
|
|
2279
|
-
* @param {string} opts.walletId the id of the wallet to sign with.
|
|
2280
|
-
* @param {string} opts.messageBase64 the base64 encoding of exact message that should be signed
|
|
2281
|
-
* @param {number} [opts.timeout] optional timeout in milliseconds. If not present, defaults to 30 seconds.
|
|
2282
|
-
* @param {string} [opts.cosmosSignDocBase64] the Cosmos `SignDoc` in base64, if applicable
|
|
2283
|
-
**/
|
|
2284
|
-
signMessage({ walletId, messageBase64, timeoutMs = 30000, cosmosSignDocBase64, }) {
|
|
2285
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2286
|
-
this.assertIsValidWalletId(walletId);
|
|
2287
|
-
const wallet = this.wallets[walletId];
|
|
2288
|
-
let signerId = this.userId;
|
|
2289
|
-
if (wallet.partnerId && !wallet.userId) {
|
|
2290
|
-
signerId = wallet.partnerId;
|
|
2291
|
-
}
|
|
2292
|
-
let signRes = yield this.signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64 });
|
|
2293
|
-
let timeStart = Date.now();
|
|
2294
|
-
if (signRes.pendingTransactionId) {
|
|
2295
|
-
this.platformUtils.openPopup(yield this.getTransactionReviewUrl(signRes.pendingTransactionId, timeoutMs), { type: cosmosSignDocBase64 ? index_js_1.PopupType.SIGN_TRANSACTION_REVIEW : index_js_1.PopupType.SIGN_MESSAGE_REVIEW });
|
|
2296
|
-
}
|
|
2297
|
-
else {
|
|
2298
|
-
(0, index_js_2.dispatchEvent)(index_js_1.ParaEvent.SIGN_MESSAGE_EVENT, signRes);
|
|
2299
|
-
return signRes;
|
|
2300
|
-
}
|
|
2301
|
-
yield new Promise(resolve => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
|
|
2302
|
-
while (true) {
|
|
2303
|
-
if (Date.now() - timeStart > timeoutMs) {
|
|
2304
|
-
break;
|
|
2305
|
-
}
|
|
2306
|
-
try {
|
|
2307
|
-
yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
|
|
2308
|
-
}
|
|
2309
|
-
catch (err) {
|
|
2310
|
-
const error = new errors_js_1.TransactionReviewDenied();
|
|
2311
|
-
(0, index_js_2.dispatchEvent)(index_js_1.ParaEvent.SIGN_MESSAGE_EVENT, signRes, error.message);
|
|
2312
|
-
throw error;
|
|
2313
|
-
}
|
|
2314
|
-
signRes = yield this.signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64 });
|
|
2315
|
-
if (signRes.pendingTransactionId) {
|
|
2316
|
-
yield new Promise(resolve => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
|
|
2317
|
-
}
|
|
2318
|
-
else {
|
|
2319
|
-
break;
|
|
2320
|
-
}
|
|
2321
|
-
}
|
|
2322
|
-
if (signRes.pendingTransactionId) {
|
|
2323
|
-
const error = new errors_js_1.TransactionReviewTimeout(yield this.getTransactionReviewUrl(signRes.pendingTransactionId), signRes.pendingTransactionId);
|
|
2324
|
-
(0, index_js_2.dispatchEvent)(index_js_1.ParaEvent.SIGN_MESSAGE_EVENT, signRes, error.message);
|
|
2325
|
-
throw error;
|
|
2326
|
-
}
|
|
2327
|
-
(0, index_js_2.dispatchEvent)(index_js_1.ParaEvent.SIGN_MESSAGE_EVENT, signRes);
|
|
2328
|
-
return signRes;
|
|
2329
|
-
});
|
|
2330
|
-
}
|
|
2331
|
-
signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64, }) {
|
|
2332
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2333
|
-
let signRes;
|
|
2334
|
-
switch (wallet.scheme) {
|
|
2335
|
-
case user_management_client_1.WalletScheme.ED25519:
|
|
2336
|
-
signRes = yield this.platformUtils.ed25519Sign(this.ctx, signerId, wallet.id, wallet.signer, messageBase64, this.retrieveSessionCookie());
|
|
2337
|
-
break;
|
|
2338
|
-
default:
|
|
2339
|
-
signRes = yield this.platformUtils.signMessage(this.ctx, signerId, wallet.id, wallet.signer, messageBase64, this.retrieveSessionCookie(), wallet.scheme === user_management_client_1.WalletScheme.DKLS, cosmosSignDocBase64);
|
|
2340
|
-
break;
|
|
2341
|
-
}
|
|
2342
|
-
return signRes;
|
|
2343
|
-
});
|
|
2344
|
-
}
|
|
2345
|
-
/**
|
|
2346
|
-
* Signs a transaction.
|
|
2347
|
-
* @param {Object} opts the options object.
|
|
2348
|
-
* @param {string} opts.walletId the id of the wallet to sign with.
|
|
2349
|
-
* @param {string} opts.rlpEncodedTxBase64 the transaction to sign, in RLP base64 encoding
|
|
2350
|
-
* @param {string} [opts.chainId] the EVM chain id of the chain the transaction is being sent on, if applicable
|
|
2351
|
-
* @param {number} [opts.timeoutMs] the amount of time to wait for the user to sign the transaction, in milliseconds
|
|
2352
|
-
**/
|
|
2353
|
-
signTransaction({ walletId, rlpEncodedTxBase64, chainId, timeoutMs = 30000, }) {
|
|
2354
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2355
|
-
this.assertIsValidWalletId(walletId);
|
|
2356
|
-
const wallet = this.wallets[walletId];
|
|
2357
|
-
let signerId = this.userId;
|
|
2358
|
-
if (wallet.partnerId && !wallet.userId) {
|
|
2359
|
-
signerId = wallet.partnerId;
|
|
2360
|
-
}
|
|
2361
|
-
let signRes = yield this.platformUtils.signTransaction(this.ctx, signerId, walletId, this.wallets[walletId].signer, rlpEncodedTxBase64, chainId, this.retrieveSessionCookie(), wallet.scheme === user_management_client_1.WalletScheme.DKLS);
|
|
2362
|
-
let timeStart = Date.now();
|
|
2363
|
-
if (signRes.pendingTransactionId) {
|
|
2364
|
-
this.platformUtils.openPopup(yield this.getTransactionReviewUrl(signRes.pendingTransactionId, timeoutMs), { type: index_js_1.PopupType.SIGN_TRANSACTION_REVIEW });
|
|
2365
|
-
}
|
|
2366
|
-
else {
|
|
2367
|
-
(0, index_js_2.dispatchEvent)(index_js_1.ParaEvent.SIGN_TRANSACTION_EVENT, signRes);
|
|
2368
|
-
return signRes;
|
|
2369
|
-
}
|
|
2370
|
-
yield new Promise(resolve => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
|
|
2371
|
-
while (true) {
|
|
2372
|
-
if (Date.now() - timeStart > timeoutMs) {
|
|
2373
|
-
break;
|
|
2374
|
-
}
|
|
2375
|
-
try {
|
|
2376
|
-
yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
|
|
2377
|
-
}
|
|
2378
|
-
catch (err) {
|
|
2379
|
-
const error = new errors_js_1.TransactionReviewDenied();
|
|
2380
|
-
(0, index_js_2.dispatchEvent)(index_js_1.ParaEvent.SIGN_TRANSACTION_EVENT, signRes, error.message);
|
|
2381
|
-
throw error;
|
|
2382
|
-
}
|
|
2383
|
-
signRes = yield this.platformUtils.signTransaction(this.ctx, signerId, walletId, this.wallets[walletId].signer, rlpEncodedTxBase64, chainId, this.retrieveSessionCookie(), wallet.scheme === user_management_client_1.WalletScheme.DKLS);
|
|
2384
|
-
if (signRes.pendingTransactionId) {
|
|
2385
|
-
yield new Promise(resolve => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
|
|
2386
|
-
}
|
|
2387
|
-
else {
|
|
2388
|
-
break;
|
|
2389
|
-
}
|
|
2390
|
-
}
|
|
2391
|
-
if (signRes.pendingTransactionId) {
|
|
2392
|
-
const error = new errors_js_1.TransactionReviewTimeout(yield this.getTransactionReviewUrl(signRes.pendingTransactionId), signRes.pendingTransactionId);
|
|
2393
|
-
(0, index_js_2.dispatchEvent)(index_js_1.ParaEvent.SIGN_TRANSACTION_EVENT, signRes, error.message);
|
|
2394
|
-
throw error;
|
|
2395
|
-
}
|
|
2396
|
-
(0, index_js_2.dispatchEvent)(index_js_1.ParaEvent.SIGN_TRANSACTION_EVENT, signRes);
|
|
2397
|
-
return signRes;
|
|
2398
|
-
});
|
|
2399
|
-
}
|
|
2400
|
-
/**
|
|
2401
|
-
* @deprecated
|
|
2402
|
-
* Sends a transaction.
|
|
2403
|
-
* @param walletId - id of the wallet to send the transaction from.
|
|
2404
|
-
* @param rlpEncodedTxBase64 - rlp encoded tx as base64 string
|
|
2405
|
-
* @param chainId - chain id of the chain the transaction is being sent on.
|
|
2406
|
-
**/
|
|
2407
|
-
sendTransaction({ walletId, rlpEncodedTxBase64, chainId, }) {
|
|
2408
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2409
|
-
this.assertIsValidWalletId(walletId);
|
|
2410
|
-
const wallet = this.wallets[walletId];
|
|
2411
|
-
const signRes = yield this.platformUtils.sendTransaction(this.ctx, this.userId, walletId, this.wallets[walletId].signer, rlpEncodedTxBase64, chainId, this.retrieveSessionCookie(), wallet.scheme === user_management_client_1.WalletScheme.DKLS);
|
|
2412
|
-
if (signRes.pendingTransactionId) {
|
|
2413
|
-
this.platformUtils.openPopup(yield this.getTransactionReviewUrl(signRes.pendingTransactionId), { type: index_js_1.PopupType.SIGN_TRANSACTION_REVIEW });
|
|
2414
|
-
const error = new errors_js_1.TransactionReviewError(yield this.getTransactionReviewUrl(signRes.pendingTransactionId));
|
|
2415
|
-
throw error;
|
|
2416
|
-
}
|
|
2417
|
-
return signRes;
|
|
2418
|
-
});
|
|
2419
|
-
}
|
|
2420
|
-
isProviderModalDisabled() {
|
|
2421
|
-
return !!this.disableProviderModal;
|
|
2422
|
-
}
|
|
2423
|
-
/**
|
|
2424
|
-
* Starts a on-ramp or off-ramp transaction and returns the Para Portal link for the user to finalize and complete it.
|
|
2425
|
-
* @param {Object} opts the options object
|
|
2426
|
-
* @param {OnRampPurchaseCreateParams} opts.params the transaction settings.
|
|
2427
|
-
* @param {boolean} opts.shouldOpenPopup if `true`, a popup window with the link will be opened.
|
|
2428
|
-
* @param {string} opts.walletId the wallet ID to use for the transaction, where funds will be sent or withdrawn.
|
|
2429
|
-
* @param {string} opts.externalWalletAddress the external wallet address to send funds to or withdraw funds from, if using an external wallet.
|
|
2430
|
-
**/
|
|
2431
|
-
initiateOnRampTransaction(options) {
|
|
2432
|
-
var _a;
|
|
2433
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2434
|
-
const { params, shouldOpenPopup } = options, walletParams = __rest(options, ["params", "shouldOpenPopup"]);
|
|
2435
|
-
const onRampPurchase = yield this.ctx.client.createOnRampPurchase(Object.assign({ userId: this.userId, params: Object.assign(Object.assign({}, params), { address: (_a = walletParams.externalWalletAddress) !== null && _a !== void 0 ? _a : this.getDisplayAddress(walletParams.walletId, { addressType: params.walletType }) }) }, walletParams));
|
|
2436
|
-
const portalUrl = yield this.getOnRampTransactionUrl(Object.assign({ purchaseId: onRampPurchase.id, providerKey: onRampPurchase.providerKey }, walletParams));
|
|
2437
|
-
if (shouldOpenPopup) {
|
|
2438
|
-
this.platformUtils.openPopup(portalUrl, { type: index_js_1.PopupType.ON_RAMP_TRANSACTION });
|
|
2439
|
-
}
|
|
2440
|
-
return { onRampPurchase, portalUrl };
|
|
2441
|
-
});
|
|
2442
|
-
}
|
|
2443
|
-
/**
|
|
2444
|
-
* Returns `true` if session was successfully kept alive, `false` otherwise.
|
|
2445
|
-
**/
|
|
2446
|
-
keepSessionAlive() {
|
|
2447
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2448
|
-
try {
|
|
2449
|
-
yield this.ctx.client.keepSessionAlive(this.userId);
|
|
2450
|
-
return true;
|
|
2451
|
-
}
|
|
2452
|
-
catch (err) {
|
|
2453
|
-
return false;
|
|
2454
|
-
}
|
|
2455
|
-
});
|
|
2456
|
-
}
|
|
2457
|
-
/**
|
|
2458
|
-
* Serialize the current session for import by another Para instance.
|
|
2459
|
-
* @returns {string} the serialized session
|
|
2460
|
-
*/
|
|
2461
|
-
exportSession() {
|
|
2462
|
-
const sessionInfo = {
|
|
2463
|
-
email: this.email,
|
|
2464
|
-
userId: this.userId,
|
|
2465
|
-
wallets: this.wallets,
|
|
2466
|
-
currentWalletIds: this.currentWalletIds,
|
|
2467
|
-
sessionCookie: this.sessionCookie,
|
|
2468
|
-
phone: this.phone,
|
|
2469
|
-
countryCode: this.countryCode,
|
|
2470
|
-
};
|
|
2471
|
-
return Buffer.from(JSON.stringify(sessionInfo)).toString('base64');
|
|
2472
|
-
}
|
|
2473
|
-
/**
|
|
2474
|
-
* Imports a session serialized by another Para instance.
|
|
2475
|
-
* @param {string} serializedInstanceBase64 the serialized session
|
|
2476
|
-
*/
|
|
2477
|
-
importSession(serializedInstanceBase64) {
|
|
2478
|
-
var _a;
|
|
2479
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2480
|
-
const serializedInstance = Buffer.from(serializedInstanceBase64, 'base64').toString('utf8');
|
|
2481
|
-
const sessionInfo = JSON.parse(serializedInstance);
|
|
2482
|
-
yield this.setEmail(sessionInfo.email);
|
|
2483
|
-
yield this.setUserId(sessionInfo.userId);
|
|
2484
|
-
yield this.setWallets(sessionInfo.wallets);
|
|
2485
|
-
for (const walletId of Object.keys(this.wallets)) {
|
|
2486
|
-
if (!this.wallets[walletId].userId) {
|
|
2487
|
-
this.wallets[walletId].userId = this.userId;
|
|
2488
|
-
}
|
|
2489
|
-
}
|
|
2490
|
-
if (Object.keys(sessionInfo.currentWalletIds).length !== 0) {
|
|
2491
|
-
yield this.setCurrentWalletIds(sessionInfo.currentWalletIds);
|
|
2492
|
-
}
|
|
2493
|
-
else {
|
|
2494
|
-
const currentWalletIds = {};
|
|
2495
|
-
for (const walletId of Object.keys(sessionInfo.wallets)) {
|
|
2496
|
-
currentWalletIds[sessionInfo.wallets[walletId].type] = [
|
|
2497
|
-
...((_a = currentWalletIds[sessionInfo.wallets[walletId].type]) !== null && _a !== void 0 ? _a : []),
|
|
2498
|
-
walletId,
|
|
2499
|
-
];
|
|
2500
|
-
}
|
|
2501
|
-
yield this.setCurrentWalletIds(currentWalletIds);
|
|
2502
|
-
}
|
|
2503
|
-
this.persistSessionCookie(sessionInfo.sessionCookie);
|
|
2504
|
-
yield this.setPhoneNumber(sessionInfo.phone, sessionInfo.countryCode);
|
|
2505
|
-
});
|
|
2506
|
-
}
|
|
2507
|
-
exitAccountCreation() {
|
|
2508
|
-
this.isAwaitingAccountCreation = false;
|
|
2509
|
-
}
|
|
2510
|
-
exitLogin() {
|
|
2511
|
-
this.isAwaitingLogin = false;
|
|
2512
|
-
}
|
|
2513
|
-
exitFarcaster() {
|
|
2514
|
-
this.isAwaitingFarcaster = false;
|
|
2515
|
-
}
|
|
2516
|
-
exitOAuth() {
|
|
2517
|
-
this.isAwaitingOAuth = false;
|
|
2518
|
-
}
|
|
2519
|
-
exitLoops() {
|
|
2520
|
-
this.exitAccountCreation();
|
|
2521
|
-
this.exitLogin();
|
|
2522
|
-
this.exitFarcaster();
|
|
2523
|
-
this.exitOAuth();
|
|
2524
|
-
}
|
|
2525
|
-
/**
|
|
2526
|
-
* Logs the user out.
|
|
2527
|
-
* @param {Object} opts the options object.
|
|
2528
|
-
* @param {boolean} opts.clearPregenWallets if `true`, will remove all pregen wallets from storage
|
|
2529
|
-
**/
|
|
2530
|
-
logout({ clearPregenWallets = false } = {}) {
|
|
2531
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2532
|
-
yield this.ctx.client.logout();
|
|
2533
|
-
yield this.clearStorage();
|
|
2534
|
-
if (!clearPregenWallets) {
|
|
2535
|
-
Object.entries(this.wallets).forEach(([id, wallet]) => {
|
|
2536
|
-
if (!wallet.pregenIdentifier) {
|
|
2537
|
-
delete this.wallets[id];
|
|
2538
|
-
}
|
|
2539
|
-
});
|
|
2540
|
-
yield this.setWallets(this.wallets);
|
|
2541
|
-
}
|
|
2542
|
-
else {
|
|
2543
|
-
this.wallets = {};
|
|
2544
|
-
}
|
|
2545
|
-
this.currentWalletIds = {};
|
|
2546
|
-
this.currentExternalWalletAddresses = undefined;
|
|
2547
|
-
this.externalWallets = {};
|
|
2548
|
-
this.loginEncryptionKeyPair = undefined;
|
|
2549
|
-
this.email = undefined;
|
|
2550
|
-
this.telegramUserId = undefined;
|
|
2551
|
-
this.phone = undefined;
|
|
2552
|
-
this.countryCode = undefined;
|
|
2553
|
-
this.userId = undefined;
|
|
2554
|
-
this.sessionCookie = undefined;
|
|
2555
|
-
(0, index_js_2.dispatchEvent)(index_js_1.ParaEvent.LOGOUT_EVENT, null);
|
|
2556
|
-
});
|
|
2557
|
-
}
|
|
2558
|
-
getSupportedCreateAuthMethods() {
|
|
2559
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2560
|
-
const res = yield this.touchSession();
|
|
2561
|
-
const partnerId = res.data.partnerId;
|
|
2562
|
-
const partnerRes = yield this.ctx.client.getPartner(partnerId);
|
|
2563
|
-
let supportedAuthMethods = new Set();
|
|
2564
|
-
for (const authMethod of partnerRes.data.partner.supportedAuthMethods) {
|
|
2565
|
-
supportedAuthMethods.add(user_management_client_1.AuthMethod[authMethod]);
|
|
2566
|
-
}
|
|
2567
|
-
return supportedAuthMethods;
|
|
2568
|
-
});
|
|
2569
|
-
}
|
|
2570
|
-
/**
|
|
2571
|
-
* Converts to a string, removing sensitive data when logging this class.
|
|
2572
|
-
*
|
|
2573
|
-
* Doesn't work for all types of logging.
|
|
2574
|
-
**/
|
|
2575
|
-
toString() {
|
|
2576
|
-
const redactedWallets = Object.keys(this.wallets).reduce((acc, walletId) => (Object.assign(Object.assign({}, acc), { [walletId]: Object.assign(Object.assign({}, this.wallets[walletId]), { signer: this.wallets[walletId].signer ? '[REDACTED]' : undefined }) })), {});
|
|
2577
|
-
const obj = {
|
|
2578
|
-
supportedWalletTypes: this.supportedWalletTypes,
|
|
2579
|
-
cosmosPrefix: this.cosmosPrefix,
|
|
2580
|
-
email: this.email,
|
|
2581
|
-
phone: this.phone,
|
|
2582
|
-
countryCode: this.countryCode,
|
|
2583
|
-
telegramUserId: this.telegramUserId,
|
|
2584
|
-
farcasterUsername: this.farcasterUsername,
|
|
2585
|
-
userId: this.userId,
|
|
2586
|
-
pregenIds: this.pregenIds,
|
|
2587
|
-
currentWalletIds: this.currentWalletIds,
|
|
2588
|
-
wallets: redactedWallets,
|
|
2589
|
-
loginEncryptionKeyPair: this.loginEncryptionKeyPair ? '[REDACTED]' : undefined,
|
|
2590
|
-
ctx: {
|
|
2591
|
-
apiKey: this.ctx.apiKey,
|
|
2592
|
-
disableWorkers: this.ctx.disableWorkers,
|
|
2593
|
-
disableWebSockets: this.ctx.disableWebSockets,
|
|
2594
|
-
env: this.ctx.env,
|
|
2595
|
-
offloadMPCComputationURL: this.ctx.offloadMPCComputationURL,
|
|
2596
|
-
useLocalFiles: this.ctx.useLocalFiles,
|
|
2597
|
-
useDKLS: this.ctx.useDKLS,
|
|
2598
|
-
cosmosPrefix: this.ctx.cosmosPrefix,
|
|
2599
|
-
},
|
|
2600
|
-
};
|
|
2601
|
-
return `Para ${JSON.stringify(obj, null, 2)}`;
|
|
2602
|
-
}
|
|
2603
|
-
}
|
|
2604
|
-
exports.ParaCore = ParaCore;
|
|
2605
|
-
_ParaCore_supportedWalletTypes = new WeakMap(), _ParaCore_supportedWalletTypesOpt = new WeakMap();
|
|
2606
|
-
ParaCore.version = constants.PARA_CORE_VERSION;
|