@getpara/core-sdk 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/ParaCore.js +247 -158
- package/dist/cjs/definitions.js +1 -3
- package/dist/cjs/external/userManagementClient.js +16 -1
- package/dist/cjs/types/events.js +17 -0
- package/dist/cjs/types/index.js +1 -0
- package/dist/esm/ParaCore.js +250 -161
- package/dist/esm/definitions.js +0 -2
- package/dist/esm/external/userManagementClient.js +14 -0
- package/dist/esm/types/events.js +14 -0
- package/dist/esm/types/index.js +1 -0
- package/dist/types/ParaCore.d.ts +218 -157
- package/dist/types/definitions.d.ts +0 -2
- package/dist/types/external/userManagementClient.d.ts +1 -0
- package/dist/types/types/events.d.ts +47 -0
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types/params.d.ts +34 -0
- package/package.json +3 -3
package/dist/esm/ParaCore.js
CHANGED
|
@@ -34,17 +34,22 @@ import { AuthMethod, PublicKeyStatus, PublicKeyType, WalletType, WalletScheme, O
|
|
|
34
34
|
import forge from 'node-forge';
|
|
35
35
|
const { pki, jsbn } = forge;
|
|
36
36
|
import { decryptWithPrivateKey, getAsymmetricKeyPair, getPublicKeyHex } from './cryptography/utils.js';
|
|
37
|
-
import {
|
|
38
|
-
import {
|
|
37
|
+
import { WalletSchemeTypeMap, getPortalBaseURL, getParaConnectBaseUrl, } from './definitions.js';
|
|
38
|
+
import { getBaseOAuthUrl, initClient } from './external/userManagementClient.js';
|
|
39
39
|
import * as mpcComputationClient from './external/mpcComputationClient.js';
|
|
40
40
|
import { distributeNewShare } from './shares/shareDistribution.js';
|
|
41
|
-
import { PopupType, } from './types/index.js';
|
|
41
|
+
import { PopupType, ParaEvent, } from './types/index.js';
|
|
42
42
|
import * as transmissionUtils from './transmission/transmissionUtils.js';
|
|
43
43
|
import { sendRecoveryForShare } from './shares/recovery.js';
|
|
44
44
|
import parsePhoneNumberFromString from 'libphonenumber-js';
|
|
45
45
|
import { getCosmosAddress, truncateAddress } from './utils/formattingUtils.js';
|
|
46
46
|
import { TransactionReviewDenied, TransactionReviewError, TransactionReviewTimeout } from './errors.js';
|
|
47
|
-
const PARA_CORE_VERSION = '0.1
|
|
47
|
+
const PARA_CORE_VERSION = '0.2.1';
|
|
48
|
+
function dispatchEvent(type, data, error) {
|
|
49
|
+
typeof window !== 'undefined' &&
|
|
50
|
+
!!window.dispatchEvent &&
|
|
51
|
+
window.dispatchEvent(new CustomEvent(type, { detail: Object.assign({ data }, (error && { error: new Error(error) })) }));
|
|
52
|
+
}
|
|
48
53
|
function isPregenIdentifierMatch(a, b, type) {
|
|
49
54
|
if (!a || !b) {
|
|
50
55
|
return false;
|
|
@@ -768,7 +773,7 @@ export class ParaCore {
|
|
|
768
773
|
this.currentExternalWalletAddresses = [address];
|
|
769
774
|
this.setCurrentExternalWalletAddresses(this.currentExternalWalletAddresses);
|
|
770
775
|
this.setExternalWallets(this.externalWallets);
|
|
771
|
-
|
|
776
|
+
dispatchEvent(ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, null);
|
|
772
777
|
});
|
|
773
778
|
}
|
|
774
779
|
/**
|
|
@@ -875,9 +880,7 @@ export class ParaCore {
|
|
|
875
880
|
if (sessionLookupId) {
|
|
876
881
|
yield this.ctx.client.setCurrentWalletIds(this.getUserId(), this.currentWalletIds, needsWallet, sessionLookupId, newDeviceSessionLookupId);
|
|
877
882
|
}
|
|
878
|
-
|
|
879
|
-
!!window.dispatchEvent &&
|
|
880
|
-
window.dispatchEvent(new Event(CURRENT_WALLET_IDS_CHANGE_EVENT));
|
|
883
|
+
dispatchEvent(ParaEvent.WALLETS_CHANGE_EVENT, null);
|
|
881
884
|
});
|
|
882
885
|
}
|
|
883
886
|
/**
|
|
@@ -1062,44 +1065,39 @@ export class ParaCore {
|
|
|
1062
1065
|
});
|
|
1063
1066
|
}
|
|
1064
1067
|
/**
|
|
1065
|
-
* Generates a URL
|
|
1066
|
-
*
|
|
1067
|
-
* @
|
|
1068
|
-
* @param loginEncryptionPublicKey - public key to use for encrypting the login encryption key
|
|
1069
|
-
* @param partnerId - id of the partner to get the portal URL for
|
|
1070
|
-
* @param newDeviceSessionId - id of the session to use for web auth for a new device
|
|
1071
|
-
* @param newDeviceEncryptionKey - public key to use for encrypting the login encryption key for a new device
|
|
1072
|
-
* @returns - web auth url
|
|
1068
|
+
* Generates a URL for registering a new WebAuth passkey.
|
|
1069
|
+
* @param {GetWebAuthUrlForLoginParams} opts the options object
|
|
1070
|
+
* @returns - the URL for creating a new passkey
|
|
1073
1071
|
*/
|
|
1074
|
-
getWebAuthURLForLogin(
|
|
1072
|
+
getWebAuthURLForLogin(opts) {
|
|
1075
1073
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1076
|
-
return this.constructPortalUrl('loginAuth',
|
|
1074
|
+
return this.constructPortalUrl('loginAuth', opts);
|
|
1077
1075
|
});
|
|
1078
1076
|
}
|
|
1079
|
-
|
|
1077
|
+
/**
|
|
1078
|
+
* Generates a URL for registering a new user password.
|
|
1079
|
+
* @param {GetWebAuthUrlForLoginParams} opts the options object
|
|
1080
|
+
* @returns - the URL for creating a new password
|
|
1081
|
+
*/
|
|
1082
|
+
getPasswordURLForLogin(opts) {
|
|
1080
1083
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1081
|
-
return this.constructPortalUrl('loginPassword',
|
|
1084
|
+
return this.constructPortalUrl('loginPassword', opts);
|
|
1082
1085
|
});
|
|
1083
1086
|
}
|
|
1084
1087
|
/**
|
|
1085
|
-
* Generates a URL
|
|
1086
|
-
*
|
|
1087
|
-
* @param sessionId - id of the session to use for web auth
|
|
1088
|
-
* @param loginEncryptionPublicKey - public key to use for encrypting the login encryption key
|
|
1089
|
-
* @param partnerId - id of the partner to get the portal URL for
|
|
1090
|
-
* @param newDeviceSessionId - id of the session to use for web auth for a new device
|
|
1091
|
-
* @param newDeviceEncryptionKey - public key to use for encrypting the login encryption key for a new device
|
|
1088
|
+
* Generates a URL for registering a new WebAuth passkey for a phone number.
|
|
1089
|
+
* @param {Omit<GetWebAuthUrlForLoginParams, 'authType'>} opts the options object
|
|
1092
1090
|
* @returns - web auth url
|
|
1093
1091
|
*/
|
|
1094
|
-
getWebAuthURLForLoginForPhone(
|
|
1092
|
+
getWebAuthURLForLoginForPhone(opts) {
|
|
1095
1093
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1096
|
-
return this.constructPortalUrl('loginAuth', Object.assign({ authType: 'phone' },
|
|
1094
|
+
return this.constructPortalUrl('loginAuth', Object.assign({ authType: 'phone' }, opts));
|
|
1097
1095
|
});
|
|
1098
1096
|
}
|
|
1099
1097
|
/**
|
|
1100
1098
|
* Gets the private key for the given wallet.
|
|
1101
|
-
* @param
|
|
1102
|
-
* @returns - private key string.
|
|
1099
|
+
* @param {string } [walletId] id of the wallet to get the private key for. Will default to the first wallet if not provided.
|
|
1100
|
+
* @returns - the private key string.
|
|
1103
1101
|
*/
|
|
1104
1102
|
getPrivateKey(walletId) {
|
|
1105
1103
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1117,7 +1115,7 @@ export class ParaCore {
|
|
|
1117
1115
|
}
|
|
1118
1116
|
/**
|
|
1119
1117
|
* Fetches the wallets associated with the user.
|
|
1120
|
-
* @returns
|
|
1118
|
+
* @returns {WalletEntity[]} wallets that were fetched.
|
|
1121
1119
|
*/
|
|
1122
1120
|
fetchWallets() {
|
|
1123
1121
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1152,28 +1150,34 @@ export class ParaCore {
|
|
|
1152
1150
|
});
|
|
1153
1151
|
}
|
|
1154
1152
|
/**
|
|
1155
|
-
* Checks if a user exists.
|
|
1156
|
-
* @
|
|
1153
|
+
* Checks if a user exists for an email address.
|
|
1154
|
+
* @param {Object} opts the options object
|
|
1155
|
+
* @param {string} opts.email the email to check.
|
|
1156
|
+
* @returns true if user exists, false otherwise.
|
|
1157
1157
|
*/
|
|
1158
|
-
checkIfUserExists(email) {
|
|
1158
|
+
checkIfUserExists({ email }) {
|
|
1159
1159
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1160
1160
|
const res = yield this.ctx.client.checkUserExists({ email });
|
|
1161
1161
|
return res.data.exists;
|
|
1162
1162
|
});
|
|
1163
1163
|
}
|
|
1164
1164
|
/**
|
|
1165
|
-
* Checks if a user exists
|
|
1166
|
-
* @
|
|
1165
|
+
* Checks if a user exists for a phone number.
|
|
1166
|
+
* @param {Object} opts the options object
|
|
1167
|
+
* @param {string} opts.phone - phone number to check.
|
|
1168
|
+
* @param {string} opts.countryCode - the country code.
|
|
1169
|
+
* @returns true if user exists, false otherwise.
|
|
1167
1170
|
*/
|
|
1168
|
-
checkIfUserExistsByPhone(phone, countryCode) {
|
|
1171
|
+
checkIfUserExistsByPhone({ phone, countryCode }) {
|
|
1169
1172
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1170
1173
|
const res = yield this.ctx.client.checkUserExists({ phone, countryCode });
|
|
1171
1174
|
return res.data.exists;
|
|
1172
1175
|
});
|
|
1173
1176
|
}
|
|
1174
|
-
|
|
1177
|
+
/**
|
|
1175
1178
|
* Creates a new user.
|
|
1176
|
-
* @param
|
|
1179
|
+
* @param {Object} opts the options object
|
|
1180
|
+
* @param {string} opts.email the email to use.
|
|
1177
1181
|
*/
|
|
1178
1182
|
createUser({ email }) {
|
|
1179
1183
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1185,8 +1189,9 @@ export class ParaCore {
|
|
|
1185
1189
|
}
|
|
1186
1190
|
/**
|
|
1187
1191
|
* Creates a new user with a phone number.
|
|
1188
|
-
* @param
|
|
1189
|
-
* @param
|
|
1192
|
+
* @param {Object} opts the options object
|
|
1193
|
+
* @param {string} opts.phone - the phone number to use for creating the user.
|
|
1194
|
+
* @param {string} opts.countryCode - the country code to use for creating the user.
|
|
1190
1195
|
*/
|
|
1191
1196
|
createUserByPhone({ phone, countryCode }) {
|
|
1192
1197
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1201,9 +1206,10 @@ export class ParaCore {
|
|
|
1201
1206
|
}
|
|
1202
1207
|
/**
|
|
1203
1208
|
* Logs in or creates a new user using an external wallet address.
|
|
1204
|
-
* @param
|
|
1205
|
-
* @param
|
|
1206
|
-
* @param
|
|
1209
|
+
* @param {Object} opts the options object
|
|
1210
|
+
* @param {string} opts.address the external wallet address to use for identification.
|
|
1211
|
+
* @param {WalletType} opts.type type of external wallet to use for identification.
|
|
1212
|
+
* @param {string} opts.provider the name of the provider for the external wallet.
|
|
1207
1213
|
*/
|
|
1208
1214
|
externalWalletLogin(wallet) {
|
|
1209
1215
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1225,10 +1231,11 @@ export class ParaCore {
|
|
|
1225
1231
|
}
|
|
1226
1232
|
/**
|
|
1227
1233
|
* Passes the email code obtained from the user for verification.
|
|
1228
|
-
* @param
|
|
1229
|
-
* @
|
|
1234
|
+
* @param {Object} opts the options object
|
|
1235
|
+
* @param {string} verificationCode the six-digit code to check
|
|
1236
|
+
* @returns {string} the web auth url for creating a new credential
|
|
1230
1237
|
*/
|
|
1231
|
-
verifyEmail(verificationCode) {
|
|
1238
|
+
verifyEmail({ verificationCode }) {
|
|
1232
1239
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1233
1240
|
yield this.ctx.client.verifyEmail(this.userId, { verificationCode });
|
|
1234
1241
|
return this.getSetUpBiometricsURL();
|
|
@@ -1236,10 +1243,11 @@ export class ParaCore {
|
|
|
1236
1243
|
}
|
|
1237
1244
|
/**
|
|
1238
1245
|
* Passes the phone code obtained from the user for verification.
|
|
1239
|
-
* @param
|
|
1240
|
-
* @
|
|
1246
|
+
* @param {Object} opts the options object
|
|
1247
|
+
* @param {string} verificationCode the six-digit code to check
|
|
1248
|
+
* @returns {string} the web auth url for creating a new credential
|
|
1241
1249
|
*/
|
|
1242
|
-
verifyPhone(verificationCode) {
|
|
1250
|
+
verifyPhone({ verificationCode }) {
|
|
1243
1251
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1244
1252
|
yield this.ctx.client.verifyPhone(this.userId, { verificationCode });
|
|
1245
1253
|
return this.getSetUpBiometricsURLForPhone();
|
|
@@ -1267,11 +1275,12 @@ export class ParaCore {
|
|
|
1267
1275
|
}
|
|
1268
1276
|
/**
|
|
1269
1277
|
* Performs 2FA verification.
|
|
1270
|
-
* @param
|
|
1271
|
-
* @param
|
|
1272
|
-
* @
|
|
1278
|
+
* @param {Object} opts the options object
|
|
1279
|
+
* @param {string} opts.email the email to use for performing a 2FA verification.
|
|
1280
|
+
* @param {string} opts.verificationCode the verification code to received via 2FA.
|
|
1281
|
+
* @returns {Object} `{ address, initiatedAt, status, userId, walletId }`
|
|
1273
1282
|
*/
|
|
1274
|
-
verify2FA(email, verificationCode) {
|
|
1283
|
+
verify2FA({ email, verificationCode }) {
|
|
1275
1284
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1276
1285
|
const res = yield this.ctx.client.verify2FA(email, verificationCode);
|
|
1277
1286
|
return {
|
|
@@ -1284,11 +1293,13 @@ export class ParaCore {
|
|
|
1284
1293
|
}
|
|
1285
1294
|
/**
|
|
1286
1295
|
* Performs 2FA verification.
|
|
1287
|
-
* @param
|
|
1288
|
-
* @param
|
|
1289
|
-
* @
|
|
1296
|
+
* @param {Object} opts the options object
|
|
1297
|
+
* @param {string} opts.phone the phone number
|
|
1298
|
+
* @param {string} opts.countryCode - the country code
|
|
1299
|
+
* @param {string} opts.verificationCode - verification code to received via 2FA.
|
|
1300
|
+
* @returns {Object} `{ address, initiatedAt, status, userId, walletId }`
|
|
1290
1301
|
*/
|
|
1291
|
-
verify2FAForPhone(phone, countryCode, verificationCode) {
|
|
1302
|
+
verify2FAForPhone({ phone, countryCode, verificationCode, }) {
|
|
1292
1303
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1293
1304
|
const res = yield this.ctx.client.verify2FAForPhone(phone, countryCode, verificationCode);
|
|
1294
1305
|
return {
|
|
@@ -1300,8 +1311,8 @@ export class ParaCore {
|
|
|
1300
1311
|
});
|
|
1301
1312
|
}
|
|
1302
1313
|
/**
|
|
1303
|
-
* Sets up
|
|
1304
|
-
* @returns uri - uri to use for setting up 2FA
|
|
1314
|
+
* Sets up two-factor authentication for the current user.
|
|
1315
|
+
* @returns {string} uri - uri to use for setting up 2FA
|
|
1305
1316
|
* */
|
|
1306
1317
|
setup2FA() {
|
|
1307
1318
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1313,16 +1324,17 @@ export class ParaCore {
|
|
|
1313
1324
|
}
|
|
1314
1325
|
/**
|
|
1315
1326
|
* Enables 2FA.
|
|
1316
|
-
* @param
|
|
1327
|
+
* @param {Object} opts the options object
|
|
1328
|
+
* @param {string} opts.verificationCode - the verification code received via 2FA.
|
|
1317
1329
|
*/
|
|
1318
|
-
enable2FA(verificationCode) {
|
|
1330
|
+
enable2FA({ verificationCode }) {
|
|
1319
1331
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1320
1332
|
yield this.ctx.client.enable2FA(this.userId, verificationCode);
|
|
1321
1333
|
});
|
|
1322
1334
|
}
|
|
1323
1335
|
/**
|
|
1324
1336
|
* Determines if 2FA has been set up.
|
|
1325
|
-
* @returns { isSetup } - true if 2FA is setup, false otherwise
|
|
1337
|
+
* @returns {Object} `{ isSetup: boolean }` - true if 2FA is setup, false otherwise
|
|
1326
1338
|
*/
|
|
1327
1339
|
check2FAStatus() {
|
|
1328
1340
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1335,11 +1347,17 @@ export class ParaCore {
|
|
|
1335
1347
|
};
|
|
1336
1348
|
});
|
|
1337
1349
|
}
|
|
1350
|
+
/**
|
|
1351
|
+
* Resend a verification email for the current user.
|
|
1352
|
+
*/
|
|
1338
1353
|
resendVerificationCode() {
|
|
1339
1354
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1340
1355
|
yield this.ctx.client.resendVerificationCode(Object.assign({ userId: this.userId }, this.getVerificationEmailProps()));
|
|
1341
1356
|
});
|
|
1342
1357
|
}
|
|
1358
|
+
/**
|
|
1359
|
+
* Resend a verification SMS for the current user.
|
|
1360
|
+
*/
|
|
1343
1361
|
resendVerificationCodeByPhone() {
|
|
1344
1362
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1345
1363
|
yield this.ctx.client.resendVerificationCodeByPhone({
|
|
@@ -1347,7 +1365,13 @@ export class ParaCore {
|
|
|
1347
1365
|
});
|
|
1348
1366
|
});
|
|
1349
1367
|
}
|
|
1350
|
-
|
|
1368
|
+
/**
|
|
1369
|
+
* Returns a URL for setting up a new WebAuth passkey.
|
|
1370
|
+
* @param {Object} opts the options object
|
|
1371
|
+
* @param {string} opts.authType - the auth type to use
|
|
1372
|
+
* @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
|
|
1373
|
+
* @returns {string} the URL
|
|
1374
|
+
*/
|
|
1351
1375
|
getSetUpBiometricsURL({ authType = 'email', isForNewDevice = false, } = {}) {
|
|
1352
1376
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1353
1377
|
const res = yield this.ctx.client.addSessionPublicKey(this.userId, {
|
|
@@ -1362,7 +1386,12 @@ export class ParaCore {
|
|
|
1362
1386
|
});
|
|
1363
1387
|
});
|
|
1364
1388
|
}
|
|
1365
|
-
|
|
1389
|
+
/**
|
|
1390
|
+
* Returns a URL for setting up a new WebAuth passkey for a phone number.
|
|
1391
|
+
* @param {Object} opts the options object
|
|
1392
|
+
* @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
|
|
1393
|
+
* @returns {string} the URL
|
|
1394
|
+
*/
|
|
1366
1395
|
getSetUpBiometricsURLForPhone({ isForNewDevice = false, } = {}) {
|
|
1367
1396
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1368
1397
|
const res = yield this.ctx.client.addSessionPublicKey(this.userId, {
|
|
@@ -1377,6 +1406,14 @@ export class ParaCore {
|
|
|
1377
1406
|
});
|
|
1378
1407
|
});
|
|
1379
1408
|
}
|
|
1409
|
+
/**
|
|
1410
|
+
* Returns a URL for setting up a new password.
|
|
1411
|
+
* @param {Object} opts the options object
|
|
1412
|
+
* @param {string} opts.authType - the auth type to use
|
|
1413
|
+
* @param {boolean} opts.isForNewDevice whether the passkey is for a new device of an existing user
|
|
1414
|
+
* @param {Theme} [opts.theme] the portal theme to use in place of the partner's default
|
|
1415
|
+
* @returns {string} the URL
|
|
1416
|
+
*/
|
|
1380
1417
|
getSetupPasswordURL({ authType = 'email', isForNewDevice = false, theme, } = {}) {
|
|
1381
1418
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1382
1419
|
const res = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
|
|
@@ -1391,6 +1428,10 @@ export class ParaCore {
|
|
|
1391
1428
|
});
|
|
1392
1429
|
});
|
|
1393
1430
|
}
|
|
1431
|
+
/**
|
|
1432
|
+
* Checks if the current session is active.
|
|
1433
|
+
* @returns `true` if active, `false` otherwise
|
|
1434
|
+
*/
|
|
1394
1435
|
isSessionActive() {
|
|
1395
1436
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1396
1437
|
if (this.isUsingExternalWallet()) {
|
|
@@ -1402,8 +1443,7 @@ export class ParaCore {
|
|
|
1402
1443
|
}
|
|
1403
1444
|
/**
|
|
1404
1445
|
* Checks if a session is active and a wallet exists.
|
|
1405
|
-
*
|
|
1406
|
-
* @returns true if session is active and a wallet exists.
|
|
1446
|
+
* @returns `true` if active, `false` otherwise
|
|
1407
1447
|
**/
|
|
1408
1448
|
isFullyLoggedIn() {
|
|
1409
1449
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1473,9 +1513,10 @@ export class ParaCore {
|
|
|
1473
1513
|
}
|
|
1474
1514
|
/**
|
|
1475
1515
|
* Initiates a login.
|
|
1476
|
-
* @param
|
|
1477
|
-
* @param
|
|
1478
|
-
* @
|
|
1516
|
+
* @param {Object} opts the options object
|
|
1517
|
+
* @param {String} opts.email - the email to login with
|
|
1518
|
+
* @param {boolean} opts.useShortURL - whether to shorten the link
|
|
1519
|
+
* @returns - the WebAuth URL for logging in
|
|
1479
1520
|
**/
|
|
1480
1521
|
initiateUserLogin(_a) {
|
|
1481
1522
|
var { useShortUrl = false } = _a, auth = __rest(_a, ["useShortUrl"]);
|
|
@@ -1514,10 +1555,11 @@ export class ParaCore {
|
|
|
1514
1555
|
}
|
|
1515
1556
|
/**
|
|
1516
1557
|
* Initiates a login.
|
|
1517
|
-
* @param
|
|
1518
|
-
* @param
|
|
1519
|
-
* @param
|
|
1520
|
-
* @
|
|
1558
|
+
* @param opts the options object
|
|
1559
|
+
* @param opts.phone the phone number
|
|
1560
|
+
* @param opts.countryCode the country code
|
|
1561
|
+
* @param opts.useShortURL - whether to shorten the link
|
|
1562
|
+
* @returns - the WebAuth URL for logging in
|
|
1521
1563
|
**/
|
|
1522
1564
|
initiateUserLoginForPhone(_a) {
|
|
1523
1565
|
var { useShortUrl = false } = _a, auth = __rest(_a, ["useShortUrl"]);
|
|
@@ -1553,6 +1595,7 @@ export class ParaCore {
|
|
|
1553
1595
|
yield new Promise(resolve => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
1554
1596
|
if (yield this.isSessionActive()) {
|
|
1555
1597
|
this.isAwaitingAccountCreation = false;
|
|
1598
|
+
dispatchEvent(ParaEvent.ACCOUNT_CREATION_EVENT, true);
|
|
1556
1599
|
return true;
|
|
1557
1600
|
}
|
|
1558
1601
|
}
|
|
@@ -1580,14 +1623,15 @@ export class ParaCore {
|
|
|
1580
1623
|
const created = yield this.createWalletPerType();
|
|
1581
1624
|
recoverySecret = recoverySecret !== null && recoverySecret !== void 0 ? recoverySecret : created.recoverySecret;
|
|
1582
1625
|
walletIds = Object.assign(Object.assign({}, walletIds), created.walletIds);
|
|
1583
|
-
|
|
1626
|
+
const resp = { walletIds, recoverySecret };
|
|
1627
|
+
dispatchEvent(ParaEvent.ACCOUNT_SETUP_EVENT, resp);
|
|
1628
|
+
return resp;
|
|
1584
1629
|
});
|
|
1585
1630
|
}
|
|
1586
1631
|
/**
|
|
1587
1632
|
* Initiates a Farcaster login attempt and return the URI for the user to connect.
|
|
1588
1633
|
* You can create a QR code with this URI that works with Farcaster's mobile app.
|
|
1589
|
-
*
|
|
1590
|
-
* @return {string}
|
|
1634
|
+
* @return {string} the Farcaster connect URI
|
|
1591
1635
|
*/
|
|
1592
1636
|
getFarcasterConnectURL() {
|
|
1593
1637
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1600,9 +1644,7 @@ export class ParaCore {
|
|
|
1600
1644
|
/**
|
|
1601
1645
|
* Awaits the response from a user's attempt to log in with Farcaster.
|
|
1602
1646
|
* If successful, this returns the user's Farcaster username and profile picture and indicates whether the user already exists.
|
|
1603
|
-
*
|
|
1604
|
-
* @param {Object} opts the options object.
|
|
1605
|
-
* @return {Object} the user's information and whether the user already exists.
|
|
1647
|
+
* @return {Object} `{userExists: boolean; username: string; pfpUrl?: string | null }` - the user's information and whether the user already exists.
|
|
1606
1648
|
*/
|
|
1607
1649
|
waitForFarcasterStatus() {
|
|
1608
1650
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1632,16 +1674,17 @@ export class ParaCore {
|
|
|
1632
1674
|
/**
|
|
1633
1675
|
* Generates a URL for the user to log in with OAuth using a desire method.
|
|
1634
1676
|
*
|
|
1635
|
-
* @param {
|
|
1677
|
+
* @param {Object} opts the options object
|
|
1678
|
+
* @param {OAuthMethod} opts.method the third-party service to use for OAuth.
|
|
1636
1679
|
* @returns {string} the URL for the user to log in with OAuth.
|
|
1637
1680
|
*/
|
|
1638
|
-
getOAuthURL(
|
|
1681
|
+
getOAuthURL({ method }) {
|
|
1639
1682
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1640
1683
|
yield this.logout();
|
|
1641
1684
|
const res = yield this.touchSession(true);
|
|
1642
1685
|
return constructUrl({
|
|
1643
|
-
base:
|
|
1644
|
-
path: `/auth/${
|
|
1686
|
+
base: method === OAuthMethod.TELEGRAM ? getPortalBaseURL(this.ctx, true) : getBaseOAuthUrl(this.ctx.env),
|
|
1687
|
+
path: `/auth/${method.toLowerCase()}`,
|
|
1645
1688
|
params: {
|
|
1646
1689
|
apiKey: this.ctx.apiKey,
|
|
1647
1690
|
sessionLookupId: res.data.sessionLookupId,
|
|
@@ -1655,7 +1698,7 @@ export class ParaCore {
|
|
|
1655
1698
|
*
|
|
1656
1699
|
* @param {Object} opts the options object.
|
|
1657
1700
|
* @param {Window} [opts.popupWindow] the popup window being used for login.
|
|
1658
|
-
* @return {Object}
|
|
1701
|
+
* @return {Object} `{ email?: string; isError?: boolean; userExists: boolean; }` the result data
|
|
1659
1702
|
*/
|
|
1660
1703
|
waitForOAuth({ popupWindow } = {}) {
|
|
1661
1704
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1672,7 +1715,7 @@ export class ParaCore {
|
|
|
1672
1715
|
const { userId, email } = res.data;
|
|
1673
1716
|
yield this.setUserId(userId);
|
|
1674
1717
|
yield this.setEmail(email);
|
|
1675
|
-
const userExists = yield this.checkIfUserExists(email);
|
|
1718
|
+
const userExists = yield this.checkIfUserExists({ email });
|
|
1676
1719
|
this.isAwaitingOAuth = false;
|
|
1677
1720
|
return {
|
|
1678
1721
|
userExists,
|
|
@@ -1694,12 +1737,12 @@ export class ParaCore {
|
|
|
1694
1737
|
* @param {Object} opts the options object
|
|
1695
1738
|
* @param {Window} [opts.popupWindow] the popup window being used for login.
|
|
1696
1739
|
* @param {boolean} [opts.skipSessionRefresh] whether to skip refreshing the session.
|
|
1697
|
-
* @returns {
|
|
1740
|
+
* @returns {Object} `{ isComplete: boolean; isError: boolean; needsWallet: boolean; partnerId: string; }` the result data
|
|
1698
1741
|
**/
|
|
1699
1742
|
waitForLoginAndSetup({ popupWindow, skipSessionRefresh = false, } = {}) {
|
|
1700
1743
|
var _a;
|
|
1701
1744
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1702
|
-
// Remove external wallets if logging in with
|
|
1745
|
+
// Remove external wallets if logging in with Capsule
|
|
1703
1746
|
this.currentExternalWalletAddresses = undefined;
|
|
1704
1747
|
this.externalWallets = {};
|
|
1705
1748
|
this.isAwaitingLogin = true;
|
|
@@ -1708,7 +1751,9 @@ export class ParaCore {
|
|
|
1708
1751
|
yield new Promise(resolve => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
1709
1752
|
if (!(yield this.isSessionActive())) {
|
|
1710
1753
|
if (popupWindow === null || popupWindow === void 0 ? void 0 : popupWindow.closed) {
|
|
1711
|
-
|
|
1754
|
+
const resp = { isComplete: false, isError: true };
|
|
1755
|
+
dispatchEvent(ParaEvent.LOGIN_EVENT, resp, 'failed to setup user');
|
|
1756
|
+
return resp;
|
|
1712
1757
|
}
|
|
1713
1758
|
continue;
|
|
1714
1759
|
}
|
|
@@ -1717,7 +1762,9 @@ export class ParaCore {
|
|
|
1717
1762
|
if (!needsWallet) {
|
|
1718
1763
|
if (this.currentWalletIdsArray.length === 0) {
|
|
1719
1764
|
if (popupWindow === null || popupWindow === void 0 ? void 0 : popupWindow.closed) {
|
|
1720
|
-
|
|
1765
|
+
const resp = { isComplete: false, isError: true };
|
|
1766
|
+
dispatchEvent(ParaEvent.LOGIN_EVENT, resp, 'failed to setup user');
|
|
1767
|
+
return resp;
|
|
1721
1768
|
}
|
|
1722
1769
|
else {
|
|
1723
1770
|
continue;
|
|
@@ -1731,11 +1778,13 @@ export class ParaCore {
|
|
|
1731
1778
|
if (tempSharesRes.data.temporaryShares.length === fetchedWallets.length) {
|
|
1732
1779
|
yield this.setupAfterLogin({ temporaryShares: tempSharesRes.data.temporaryShares, skipSessionRefresh });
|
|
1733
1780
|
yield this.claimPregenWallets();
|
|
1734
|
-
|
|
1781
|
+
const resp = {
|
|
1735
1782
|
isComplete: true,
|
|
1736
1783
|
needsWallet: needsWallet || Object.values(this.wallets).length === 0,
|
|
1737
1784
|
partnerId: postLoginData.data.partnerId,
|
|
1738
1785
|
};
|
|
1786
|
+
dispatchEvent(ParaEvent.LOGIN_EVENT, resp);
|
|
1787
|
+
return resp;
|
|
1739
1788
|
}
|
|
1740
1789
|
}
|
|
1741
1790
|
catch (err) {
|
|
@@ -1743,7 +1792,9 @@ export class ParaCore {
|
|
|
1743
1792
|
console.error(err);
|
|
1744
1793
|
}
|
|
1745
1794
|
}
|
|
1746
|
-
|
|
1795
|
+
const resp = { isComplete: false };
|
|
1796
|
+
dispatchEvent(ParaEvent.LOGIN_EVENT, resp, 'exitted login without setting up user');
|
|
1797
|
+
return resp;
|
|
1747
1798
|
});
|
|
1748
1799
|
}
|
|
1749
1800
|
/**
|
|
@@ -1752,7 +1803,7 @@ export class ParaCore {
|
|
|
1752
1803
|
*
|
|
1753
1804
|
* @param {Object} opts the options object.
|
|
1754
1805
|
* @param {boolean} [shouldOpenPopup] - if `true`, the running device will open a popup to reauthenticate the user.
|
|
1755
|
-
* @returns
|
|
1806
|
+
* @returns a URL for the user to reauthenticate.
|
|
1756
1807
|
**/
|
|
1757
1808
|
refreshSession({ shouldOpenPopup = false } = {}) {
|
|
1758
1809
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1787,8 +1838,8 @@ export class ParaCore {
|
|
|
1787
1838
|
}
|
|
1788
1839
|
/**
|
|
1789
1840
|
* Get transmission shares associated with session.
|
|
1790
|
-
*
|
|
1791
|
-
* @param isForNewDevice - true if this device is registering.
|
|
1841
|
+
* @param {Object} opts the options object.
|
|
1842
|
+
* @param {boolean} opts.isForNewDevice - true if this device is registering.
|
|
1792
1843
|
* @returns - transmission keyshares.
|
|
1793
1844
|
**/
|
|
1794
1845
|
getTransmissionKeyShares({ isForNewDevice = false } = {}) {
|
|
@@ -1800,8 +1851,9 @@ export class ParaCore {
|
|
|
1800
1851
|
}
|
|
1801
1852
|
/**
|
|
1802
1853
|
* Call this method after login to perform setup.
|
|
1803
|
-
*
|
|
1804
|
-
* @param temporaryShares
|
|
1854
|
+
* @param {Object} opts the options object.
|
|
1855
|
+
* @param {any[]} opts.temporaryShares optional temporary shares to use for decryption.
|
|
1856
|
+
* @param {boolean} [opts.skipSessionRefresh] - whether or not to skip refreshing the session.
|
|
1805
1857
|
**/
|
|
1806
1858
|
setupAfterLogin({ temporaryShares, skipSessionRefresh = false, } = {}) {
|
|
1807
1859
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1822,12 +1874,12 @@ export class ParaCore {
|
|
|
1822
1874
|
}
|
|
1823
1875
|
/**
|
|
1824
1876
|
* Distributes a new wallet recovery share.
|
|
1825
|
-
*
|
|
1826
|
-
* @param walletId
|
|
1827
|
-
* @param userShare
|
|
1828
|
-
* @param skipBiometricShareCreation
|
|
1829
|
-
* @param forceRefreshRecovery
|
|
1830
|
-
* @returns
|
|
1877
|
+
* @param {Object} opts the options object.
|
|
1878
|
+
* @param {string} opts.walletId the wallet to distribute the recovery share for.
|
|
1879
|
+
* @param {string} opts.userShare optional user share generate the recovery share from. Defaults to the signer from the passed in walletId
|
|
1880
|
+
* @param {boolean} opts.skipBiometricShareCreation whether or not to skip biometric share creation. Used when regenerating recovery shares.
|
|
1881
|
+
* @param {boolean} opts.forceRefreshRecovery whether or not to force recovery secret regeneration. Used when regenerating recovery shares.
|
|
1882
|
+
* @returns {string} the recovery share.
|
|
1831
1883
|
**/
|
|
1832
1884
|
distributeNewWalletShare({ walletId, userShare, skipBiometricShareCreation = false, forceRefresh = false, }) {
|
|
1833
1885
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1971,10 +2023,10 @@ export class ParaCore {
|
|
|
1971
2023
|
}
|
|
1972
2024
|
/**
|
|
1973
2025
|
* Creates a new wallet.
|
|
1974
|
-
*
|
|
1975
|
-
* @param
|
|
1976
|
-
* @param
|
|
1977
|
-
* @returns [wallet, recoveryShare]
|
|
2026
|
+
* @param {Object} opts the options object.
|
|
2027
|
+
* @param {WalletType} opts.type the type of wallet to create.
|
|
2028
|
+
* @param {boolean} opts.skipDistribute - if true, recovery share will not be distributed.
|
|
2029
|
+
* @returns {[Wallet, string | null]} `[wallet, recoveryShare]` - the wallet object and the new recovery share.
|
|
1978
2030
|
**/
|
|
1979
2031
|
createWallet({ type: _type, skipDistribute = false, } = {}) {
|
|
1980
2032
|
var _a, _b;
|
|
@@ -2016,6 +2068,12 @@ export class ParaCore {
|
|
|
2016
2068
|
});
|
|
2017
2069
|
}
|
|
2018
2070
|
yield this.setCurrentWalletIds(Object.assign(Object.assign({}, this.currentWalletIds), { [walletType]: [...((_b = this.currentWalletIds[walletType]) !== null && _b !== void 0 ? _b : []), walletId] }));
|
|
2071
|
+
const walletNoSigner = Object.assign({}, wallet);
|
|
2072
|
+
delete walletNoSigner.signer;
|
|
2073
|
+
dispatchEvent(ParaEvent.WALLET_CREATED, {
|
|
2074
|
+
wallet: walletNoSigner,
|
|
2075
|
+
recoverySecret: recoveryShare,
|
|
2076
|
+
});
|
|
2019
2077
|
return [wallet, recoveryShare];
|
|
2020
2078
|
});
|
|
2021
2079
|
}
|
|
@@ -2028,7 +2086,7 @@ export class ParaCore {
|
|
|
2028
2086
|
* @param {WalletType} [opts.type] the type of wallet to create. Defaults to the first non-optional type in the instance's `supportedWalletTypes` array.
|
|
2029
2087
|
* @returns {Wallet} the created wallet.
|
|
2030
2088
|
**/
|
|
2031
|
-
|
|
2089
|
+
createPregenWallet(opts) {
|
|
2032
2090
|
var _a, _b;
|
|
2033
2091
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2034
2092
|
const { type: _type = (_a = this.supportedWalletTypes.find(({ optional }) => !optional)) === null || _a === void 0 ? void 0 : _a.type, pregenIdentifier, pregenIdentifierType = 'EMAIL', } = opts;
|
|
@@ -2062,17 +2120,17 @@ export class ParaCore {
|
|
|
2062
2120
|
* Creates new pregenerated wallets for each desired type.
|
|
2063
2121
|
* If no types are provided, this method will create one for each of the non-optional types
|
|
2064
2122
|
* specified in the instance's `supportedWalletTypes` array that are not already present.
|
|
2065
|
-
*
|
|
2066
|
-
* @param {string} pregenIdentifier the identifier to associate each wallet with.
|
|
2067
|
-
* @param {TPregenIdentifierType} pregenIdentifierType - either `'EMAIL'` or `'PHONE'`.
|
|
2068
|
-
* @param {WalletType[]} [types] the wallet types to create. Defaults to any types the instance supports that are not already present.
|
|
2069
|
-
* @returns an array containing the created wallets.
|
|
2123
|
+
* @param {Object} opts the options object.
|
|
2124
|
+
* @param {string} opts.pregenIdentifier the identifier to associate each wallet with.
|
|
2125
|
+
* @param {TPregenIdentifierType} opts.pregenIdentifierType - either `'EMAIL'` or `'PHONE'`.
|
|
2126
|
+
* @param {WalletType[]} [opts.types] the wallet types to create. Defaults to any types the instance supports that are not already present.
|
|
2127
|
+
* @returns {Wallet[]} an array containing the created wallets.
|
|
2070
2128
|
**/
|
|
2071
2129
|
createPregenWalletPerType({ types, pregenIdentifier, pregenIdentifierType = 'EMAIL', }) {
|
|
2072
2130
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2073
2131
|
const wallets = [];
|
|
2074
2132
|
for (const type of yield this.getTypesToCreate(types)) {
|
|
2075
|
-
const wallet = yield this.
|
|
2133
|
+
const wallet = yield this.createPregenWallet({ type, pregenIdentifier, pregenIdentifierType });
|
|
2076
2134
|
wallets.push(wallet);
|
|
2077
2135
|
}
|
|
2078
2136
|
return wallets;
|
|
@@ -2081,11 +2139,12 @@ export class ParaCore {
|
|
|
2081
2139
|
/**
|
|
2082
2140
|
* Claims a pregenerated wallet.
|
|
2083
2141
|
*
|
|
2084
|
-
* @param
|
|
2085
|
-
* @param
|
|
2086
|
-
* @
|
|
2142
|
+
* @param {Object} opts the options object.
|
|
2143
|
+
* @param {string} opts.pregenIdentifier string the identifier of the user claiming the wallet
|
|
2144
|
+
* @param {TPregenIdentifierType} opts.pregenIdentifierType type of the identifier of the user claiming the wallet
|
|
2145
|
+
* @returns {[Wallet, string | null]} `[wallet, recoveryShare]` - the wallet object and the new recovery share.
|
|
2087
2146
|
**/
|
|
2088
|
-
claimPregenWallets(pregenIdentifier, pregenIdentifierType = !!pregenIdentifier ? 'EMAIL' : undefined) {
|
|
2147
|
+
claimPregenWallets({ pregenIdentifier, pregenIdentifierType = !!pregenIdentifier ? 'EMAIL' : undefined, } = {}) {
|
|
2089
2148
|
var _a;
|
|
2090
2149
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2091
2150
|
this.requireApiKey();
|
|
@@ -2129,17 +2188,23 @@ export class ParaCore {
|
|
|
2129
2188
|
}
|
|
2130
2189
|
}
|
|
2131
2190
|
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 });
|
|
2191
|
+
const walletNoSigner = Object.assign({}, this.wallets[wallet.id]);
|
|
2192
|
+
delete walletNoSigner.signer;
|
|
2193
|
+
dispatchEvent(ParaEvent.PREGEN_WALLET_CLAIMED, {
|
|
2194
|
+
wallet: walletNoSigner,
|
|
2195
|
+
recoverySecret: newRecoverySecret,
|
|
2196
|
+
});
|
|
2132
2197
|
}
|
|
2133
2198
|
yield this.setWallets(this.wallets);
|
|
2134
2199
|
return newRecoverySecret;
|
|
2135
2200
|
});
|
|
2136
2201
|
}
|
|
2137
2202
|
/**
|
|
2138
|
-
* Updates a
|
|
2139
|
-
*
|
|
2140
|
-
* @param
|
|
2141
|
-
* @param
|
|
2142
|
-
* @
|
|
2203
|
+
* Updates the identifier for a pregen wallet.
|
|
2204
|
+
* @param {Object} opts the options object.
|
|
2205
|
+
* @param {string} opts.walletId the pregen wallet ID
|
|
2206
|
+
* @param {string} opts.newPregenIdentifier the new identtifier
|
|
2207
|
+
* @param {TPregenIdentifierType} opts.newPregenIdentifierType: the new identifier type
|
|
2143
2208
|
**/
|
|
2144
2209
|
updatePregenWalletIdentifier({ walletId, newPregenIdentifier, newPregenIdentifierType, }) {
|
|
2145
2210
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -2155,11 +2220,11 @@ export class ParaCore {
|
|
|
2155
2220
|
});
|
|
2156
2221
|
}
|
|
2157
2222
|
/**
|
|
2158
|
-
* Checks if
|
|
2159
|
-
*
|
|
2160
|
-
* @param pregenIdentifier string the identifier of the user claiming the wallet
|
|
2161
|
-
* @param pregenIdentifierType type of the string of the identifier of the user claiming the wallet
|
|
2162
|
-
* @returns
|
|
2223
|
+
* Checks if a pregen Wallet exists for the given identifier with the current partner.
|
|
2224
|
+
* @param {Object} opts the options object.
|
|
2225
|
+
* @param {string} opts.pregenIdentifier string the identifier of the user claiming the wallet
|
|
2226
|
+
* @param {TPregenIdentifierType} opts.pregenIdentifierType type of the string of the identifier of the user claiming the wallet
|
|
2227
|
+
* @returns {boolean} whether the pregen wallet exists
|
|
2163
2228
|
**/
|
|
2164
2229
|
hasPregenWallet({ pregenIdentifier, pregenIdentifierType, }) {
|
|
2165
2230
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -2174,11 +2239,11 @@ export class ParaCore {
|
|
|
2174
2239
|
});
|
|
2175
2240
|
}
|
|
2176
2241
|
/**
|
|
2177
|
-
* Get pregen wallets for the identifier
|
|
2178
|
-
*
|
|
2179
|
-
* @param {string} pregenIdentifier - the identifier of the user claiming the wallet
|
|
2180
|
-
* @param {TPregenIdentifierType} pregenIdentifierType - type of the identifier of the user claiming the wallet
|
|
2181
|
-
* @returns {Promise<WalletEntity[]>}
|
|
2242
|
+
* Get pregen wallets for the given identifier.
|
|
2243
|
+
* @param {Object} opts the options object.
|
|
2244
|
+
* @param {string} opts.pregenIdentifier - the identifier of the user claiming the wallet
|
|
2245
|
+
* @param {TPregenIdentifierType} opts.pregenIdentifierType - type of the identifier of the user claiming the wallet
|
|
2246
|
+
* @returns {Promise<WalletEntity[]>} the array of found wallets
|
|
2182
2247
|
**/
|
|
2183
2248
|
getPregenWallets({ pregenIdentifier, pregenIdentifierType = !!pregenIdentifier ? 'EMAIL' : undefined, } = {}) {
|
|
2184
2249
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -2193,9 +2258,8 @@ export class ParaCore {
|
|
|
2193
2258
|
return base64Wallet;
|
|
2194
2259
|
}
|
|
2195
2260
|
/**
|
|
2196
|
-
*
|
|
2197
|
-
*
|
|
2198
|
-
* @returns string base64 encoded wallet
|
|
2261
|
+
* Encodes the current wallets encoded in Base 64.
|
|
2262
|
+
* @returns {string} the encoded wallet string
|
|
2199
2263
|
**/
|
|
2200
2264
|
getUserShare() {
|
|
2201
2265
|
if (Object.values(this.wallets).length === 0) {
|
|
@@ -2206,10 +2270,8 @@ export class ParaCore {
|
|
|
2206
2270
|
.join('-');
|
|
2207
2271
|
}
|
|
2208
2272
|
/**
|
|
2209
|
-
* Sets
|
|
2210
|
-
*
|
|
2211
|
-
* @param base64Wallet
|
|
2212
|
-
* @returns Promise<void>
|
|
2273
|
+
* Sets the current wallets from a Base 64 string.
|
|
2274
|
+
* @param {string} base64Wallet the encoded wallet string
|
|
2213
2275
|
**/
|
|
2214
2276
|
setUserShare(base64Wallets) {
|
|
2215
2277
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -2256,13 +2318,15 @@ export class ParaCore {
|
|
|
2256
2318
|
});
|
|
2257
2319
|
}
|
|
2258
2320
|
/**
|
|
2259
|
-
* Signs a message.
|
|
2321
|
+
* Signs a message using one of the current wallets.
|
|
2260
2322
|
*
|
|
2261
2323
|
* If you want to sign the keccak256 hash of a message, hash the
|
|
2262
2324
|
* message first and then pass in the base64 encoded hash.
|
|
2263
|
-
* @param
|
|
2264
|
-
* @param
|
|
2265
|
-
* @param
|
|
2325
|
+
* @param {Object} opts the options object.
|
|
2326
|
+
* @param {string} opts.walletId the id of the wallet to sign with.
|
|
2327
|
+
* @param {string} opts.messageBase64 the base64 encoding of exact message that should be signed
|
|
2328
|
+
* @param {number} [opts.timeout] optional timeout in milliseconds. If not present, defaults to 30 seconds.
|
|
2329
|
+
* @param {string} [opts.cosmosSignDocBase64] the Cosmos `SignDoc` in base64, if applicable
|
|
2266
2330
|
**/
|
|
2267
2331
|
signMessage({ walletId, messageBase64, timeoutMs = 30000, cosmosSignDocBase64, }) {
|
|
2268
2332
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -2278,6 +2342,7 @@ export class ParaCore {
|
|
|
2278
2342
|
this.platformUtils.openPopup(yield this.getTransactionReviewUrl(signRes.pendingTransactionId, timeoutMs), { type: cosmosSignDocBase64 ? PopupType.SIGN_TRANSACTION_REVIEW : PopupType.SIGN_MESSAGE_REVIEW });
|
|
2279
2343
|
}
|
|
2280
2344
|
else {
|
|
2345
|
+
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes);
|
|
2281
2346
|
return signRes;
|
|
2282
2347
|
}
|
|
2283
2348
|
yield new Promise(resolve => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
@@ -2289,7 +2354,9 @@ export class ParaCore {
|
|
|
2289
2354
|
yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
|
|
2290
2355
|
}
|
|
2291
2356
|
catch (err) {
|
|
2292
|
-
|
|
2357
|
+
const error = new TransactionReviewDenied();
|
|
2358
|
+
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes, error.message);
|
|
2359
|
+
throw error;
|
|
2293
2360
|
}
|
|
2294
2361
|
signRes = yield this.signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64 });
|
|
2295
2362
|
if (signRes.pendingTransactionId) {
|
|
@@ -2300,8 +2367,11 @@ export class ParaCore {
|
|
|
2300
2367
|
}
|
|
2301
2368
|
}
|
|
2302
2369
|
if (signRes.pendingTransactionId) {
|
|
2303
|
-
|
|
2370
|
+
const error = new TransactionReviewTimeout(yield this.getTransactionReviewUrl(signRes.pendingTransactionId), signRes.pendingTransactionId);
|
|
2371
|
+
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes, error.message);
|
|
2372
|
+
throw error;
|
|
2304
2373
|
}
|
|
2374
|
+
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes);
|
|
2305
2375
|
return signRes;
|
|
2306
2376
|
});
|
|
2307
2377
|
}
|
|
@@ -2321,9 +2391,11 @@ export class ParaCore {
|
|
|
2321
2391
|
}
|
|
2322
2392
|
/**
|
|
2323
2393
|
* Signs a transaction.
|
|
2324
|
-
* @param
|
|
2325
|
-
* @param
|
|
2326
|
-
* @param
|
|
2394
|
+
* @param {Object} opts the options object.
|
|
2395
|
+
* @param {string} opts.walletId the id of the wallet to sign with.
|
|
2396
|
+
* @param {string} opts.rlpEncodedTxBase64 the transaction to sign, in RLP base64 encoding
|
|
2397
|
+
* @param {string} [opts.chainId] the EVM chain id of the chain the transaction is being sent on, if applicable
|
|
2398
|
+
* @param {number} [opts.timeoutMs] the amount of time to wait for the user to sign the transaction, in milliseconds
|
|
2327
2399
|
**/
|
|
2328
2400
|
signTransaction({ walletId, rlpEncodedTxBase64, chainId, timeoutMs = 30000, }) {
|
|
2329
2401
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -2339,6 +2411,7 @@ export class ParaCore {
|
|
|
2339
2411
|
this.platformUtils.openPopup(yield this.getTransactionReviewUrl(signRes.pendingTransactionId, timeoutMs), { type: PopupType.SIGN_TRANSACTION_REVIEW });
|
|
2340
2412
|
}
|
|
2341
2413
|
else {
|
|
2414
|
+
dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes);
|
|
2342
2415
|
return signRes;
|
|
2343
2416
|
}
|
|
2344
2417
|
yield new Promise(resolve => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
@@ -2350,7 +2423,9 @@ export class ParaCore {
|
|
|
2350
2423
|
yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
|
|
2351
2424
|
}
|
|
2352
2425
|
catch (err) {
|
|
2353
|
-
|
|
2426
|
+
const error = new TransactionReviewDenied();
|
|
2427
|
+
dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes, error.message);
|
|
2428
|
+
throw error;
|
|
2354
2429
|
}
|
|
2355
2430
|
signRes = yield this.platformUtils.signTransaction(this.ctx, signerId, walletId, this.wallets[walletId].signer, rlpEncodedTxBase64, chainId, this.retrieveSessionCookie(), wallet.scheme === WalletScheme.DKLS);
|
|
2356
2431
|
if (signRes.pendingTransactionId) {
|
|
@@ -2361,12 +2436,16 @@ export class ParaCore {
|
|
|
2361
2436
|
}
|
|
2362
2437
|
}
|
|
2363
2438
|
if (signRes.pendingTransactionId) {
|
|
2364
|
-
|
|
2439
|
+
const error = new TransactionReviewTimeout(yield this.getTransactionReviewUrl(signRes.pendingTransactionId), signRes.pendingTransactionId);
|
|
2440
|
+
dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes, error.message);
|
|
2441
|
+
throw error;
|
|
2365
2442
|
}
|
|
2443
|
+
dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes);
|
|
2366
2444
|
return signRes;
|
|
2367
2445
|
});
|
|
2368
2446
|
}
|
|
2369
2447
|
/**
|
|
2448
|
+
* @deprecated
|
|
2370
2449
|
* Sends a transaction.
|
|
2371
2450
|
* @param walletId - id of the wallet to send the transaction from.
|
|
2372
2451
|
* @param rlpEncodedTxBase64 - rlp encoded tx as base64 string
|
|
@@ -2379,7 +2458,8 @@ export class ParaCore {
|
|
|
2379
2458
|
const signRes = yield this.platformUtils.sendTransaction(this.ctx, this.userId, walletId, this.wallets[walletId].signer, rlpEncodedTxBase64, chainId, this.retrieveSessionCookie(), wallet.scheme === WalletScheme.DKLS);
|
|
2380
2459
|
if (signRes.pendingTransactionId) {
|
|
2381
2460
|
this.platformUtils.openPopup(yield this.getTransactionReviewUrl(signRes.pendingTransactionId), { type: PopupType.SIGN_TRANSACTION_REVIEW });
|
|
2382
|
-
|
|
2461
|
+
const error = new TransactionReviewError(yield this.getTransactionReviewUrl(signRes.pendingTransactionId));
|
|
2462
|
+
throw error;
|
|
2383
2463
|
}
|
|
2384
2464
|
return signRes;
|
|
2385
2465
|
});
|
|
@@ -2389,11 +2469,11 @@ export class ParaCore {
|
|
|
2389
2469
|
}
|
|
2390
2470
|
/**
|
|
2391
2471
|
* Starts a on-ramp or off-ramp transaction and returns the Para Portal link for the user to finalize and complete it.
|
|
2392
|
-
* @param {Object}
|
|
2393
|
-
* @param {OnRampPurchaseCreateParams}
|
|
2394
|
-
* @param {boolean}
|
|
2395
|
-
* @param {string}
|
|
2396
|
-
* @param {string}
|
|
2472
|
+
* @param {Object} opts the options object
|
|
2473
|
+
* @param {OnRampPurchaseCreateParams} opts.params the transaction settings.
|
|
2474
|
+
* @param {boolean} opts.shouldOpenPopup if `true`, a popup window with the link will be opened.
|
|
2475
|
+
* @param {string} opts.walletId the wallet ID to use for the transaction, where funds will be sent or withdrawn.
|
|
2476
|
+
* @param {string} opts.externalWalletAddress the external wallet address to send funds to or withdraw funds from, if using an external wallet.
|
|
2397
2477
|
**/
|
|
2398
2478
|
initiateOnRampTransaction(options) {
|
|
2399
2479
|
var _a;
|
|
@@ -2408,7 +2488,7 @@ export class ParaCore {
|
|
|
2408
2488
|
});
|
|
2409
2489
|
}
|
|
2410
2490
|
/**
|
|
2411
|
-
* Returns true if session was successfully kept alive, false otherwise.
|
|
2491
|
+
* Returns `true` if session was successfully kept alive, `false` otherwise.
|
|
2412
2492
|
**/
|
|
2413
2493
|
keepSessionAlive() {
|
|
2414
2494
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -2421,6 +2501,10 @@ export class ParaCore {
|
|
|
2421
2501
|
}
|
|
2422
2502
|
});
|
|
2423
2503
|
}
|
|
2504
|
+
/**
|
|
2505
|
+
* Serialize the current session for import by another Para instance.
|
|
2506
|
+
* @returns {string} the serialized session
|
|
2507
|
+
*/
|
|
2424
2508
|
exportSession() {
|
|
2425
2509
|
const sessionInfo = {
|
|
2426
2510
|
email: this.email,
|
|
@@ -2433,6 +2517,10 @@ export class ParaCore {
|
|
|
2433
2517
|
};
|
|
2434
2518
|
return Buffer.from(JSON.stringify(sessionInfo)).toString('base64');
|
|
2435
2519
|
}
|
|
2520
|
+
/**
|
|
2521
|
+
* Imports a session serialized by another Para instance.
|
|
2522
|
+
* @param {string} serializedInstanceBase64 the serialized session
|
|
2523
|
+
*/
|
|
2436
2524
|
importSession(serializedInstanceBase64) {
|
|
2437
2525
|
var _a;
|
|
2438
2526
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -2483,8 +2571,8 @@ export class ParaCore {
|
|
|
2483
2571
|
}
|
|
2484
2572
|
/**
|
|
2485
2573
|
* Logs the user out.
|
|
2486
|
-
*
|
|
2487
|
-
* @param
|
|
2574
|
+
* @param {Object} opts the options object.
|
|
2575
|
+
* @param {boolean} opts.clearPregenWallets if `true`, will remove all pregen wallets from storage
|
|
2488
2576
|
**/
|
|
2489
2577
|
logout({ clearPregenWallets = false } = {}) {
|
|
2490
2578
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -2511,6 +2599,7 @@ export class ParaCore {
|
|
|
2511
2599
|
this.countryCode = undefined;
|
|
2512
2600
|
this.userId = undefined;
|
|
2513
2601
|
this.sessionCookie = undefined;
|
|
2602
|
+
dispatchEvent(ParaEvent.LOGOUT_EVENT, null);
|
|
2514
2603
|
});
|
|
2515
2604
|
}
|
|
2516
2605
|
getSupportedCreateAuthMethods() {
|