@getpara/core-sdk 2.0.0-alpha.3 → 2.0.0-alpha.5
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 +3023 -0
- package/dist/cjs/PlatformUtils.js +15 -0
- package/dist/cjs/StorageUtils.js +15 -0
- package/dist/cjs/constants.js +84 -0
- package/dist/cjs/cryptography/utils.js +350 -0
- package/dist/cjs/errors.js +51 -0
- package/dist/cjs/external/mpcComputationClient.js +62 -0
- package/dist/cjs/external/userManagementClient.js +106 -0
- package/dist/cjs/index.js +85 -4001
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/shares/KeyContainer.js +89 -0
- package/dist/cjs/shares/recovery.js +127 -0
- package/dist/cjs/shares/shareDistribution.js +104 -0
- package/dist/cjs/transmission/transmissionUtils.js +93 -0
- package/dist/cjs/types/config.js +43 -0
- package/dist/cjs/types/coreApi.js +74 -0
- package/dist/cjs/types/events.js +41 -0
- package/dist/cjs/types/index.js +52 -0
- package/dist/cjs/types/methods.js +15 -0
- package/dist/cjs/types/onRamps.js +33 -0
- package/dist/cjs/types/popup.js +35 -0
- package/dist/cjs/types/recovery.js +34 -0
- package/dist/cjs/types/theme.js +15 -0
- package/dist/cjs/types/wallet.js +31 -0
- package/dist/cjs/utils/autobind.js +41 -0
- package/dist/cjs/utils/events.js +45 -0
- package/dist/cjs/utils/formatting.js +112 -0
- package/dist/cjs/utils/index.js +41 -0
- package/dist/cjs/utils/json.js +37 -0
- package/dist/cjs/utils/listeners.js +71 -0
- package/dist/cjs/utils/onRamps.js +92 -0
- package/dist/cjs/utils/phone.js +61 -0
- package/dist/cjs/utils/polling.js +58 -0
- package/dist/cjs/utils/types.js +29 -0
- package/dist/cjs/utils/url.js +135 -0
- package/dist/cjs/utils/wallet.js +159 -0
- package/dist/esm/ParaCore.js +2984 -0
- package/dist/esm/PlatformUtils.js +0 -0
- package/dist/esm/StorageUtils.js +0 -0
- package/dist/esm/chunk-7B52C2XE.js +70 -0
- package/dist/esm/constants.js +43 -0
- package/dist/esm/cryptography/utils.js +282 -0
- package/dist/esm/errors.js +27 -0
- package/dist/esm/external/mpcComputationClient.js +30 -0
- package/dist/esm/external/userManagementClient.js +71 -0
- package/dist/esm/index.js +58 -3965
- package/dist/esm/package.json +4 -0
- package/dist/esm/shares/KeyContainer.js +57 -0
- package/dist/esm/shares/recovery.js +74 -0
- package/dist/esm/shares/shareDistribution.js +64 -0
- package/dist/esm/transmission/transmissionUtils.js +42 -0
- package/dist/esm/types/config.js +20 -0
- package/dist/esm/types/coreApi.js +52 -0
- package/dist/esm/types/events.js +19 -0
- package/dist/esm/types/index.js +22 -0
- package/dist/esm/types/methods.js +0 -0
- package/dist/esm/types/onRamps.js +11 -0
- package/dist/esm/types/popup.js +13 -0
- package/dist/esm/types/recovery.js +12 -0
- package/dist/esm/types/theme.js +0 -0
- package/dist/esm/types/wallet.js +9 -0
- package/dist/esm/utils/autobind.js +19 -0
- package/dist/esm/utils/events.js +11 -0
- package/dist/esm/utils/formatting.js +74 -0
- package/dist/esm/utils/index.js +11 -0
- package/dist/esm/utils/json.js +15 -0
- package/dist/esm/utils/listeners.js +38 -0
- package/dist/esm/utils/onRamps.js +66 -0
- package/dist/esm/utils/phone.js +28 -0
- package/dist/esm/utils/polling.js +18 -0
- package/dist/esm/utils/types.js +7 -0
- package/dist/esm/utils/url.js +90 -0
- package/dist/esm/utils/wallet.js +103 -0
- package/dist/types/ParaCore.d.ts +157 -126
- package/dist/types/PlatformUtils.d.ts +4 -3
- package/dist/types/constants.d.ts +2 -0
- package/dist/types/index.d.ts +3 -3
- package/dist/types/types/config.d.ts +4 -5
- package/dist/types/types/coreApi.d.ts +47 -9
- package/dist/types/types/events.d.ts +4 -1
- package/dist/types/types/methods.d.ts +9 -4
- package/dist/types/types/onRamps.d.ts +3 -3
- package/dist/types/types/wallet.d.ts +4 -2
- package/dist/types/utils/formatting.d.ts +3 -2
- package/dist/types/utils/onRamps.d.ts +12 -5
- package/dist/types/utils/wallet.d.ts +8 -7
- package/package.json +7 -7
- package/dist/cjs/index.js.br +0 -0
- package/dist/cjs/index.js.gz +0 -0
- package/dist/esm/index.js.br +0 -0
- package/dist/esm/index.js.gz +0 -0
package/dist/esm/index.js
CHANGED
|
@@ -1,4000 +1,99 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __typeError = (msg) => {
|
|
8
|
-
throw TypeError(msg);
|
|
9
|
-
};
|
|
10
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
-
var __spreadValues = (a, b) => {
|
|
12
|
-
for (var prop in b || (b = {}))
|
|
13
|
-
if (__hasOwnProp.call(b, prop))
|
|
14
|
-
__defNormalProp(a, prop, b[prop]);
|
|
15
|
-
if (__getOwnPropSymbols)
|
|
16
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
-
if (__propIsEnum.call(b, prop))
|
|
18
|
-
__defNormalProp(a, prop, b[prop]);
|
|
19
|
-
}
|
|
20
|
-
return a;
|
|
21
|
-
};
|
|
22
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
|
-
var __objRest = (source, exclude) => {
|
|
24
|
-
var target = {};
|
|
25
|
-
for (var prop in source)
|
|
26
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
27
|
-
target[prop] = source[prop];
|
|
28
|
-
if (source != null && __getOwnPropSymbols)
|
|
29
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
30
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
31
|
-
target[prop] = source[prop];
|
|
32
|
-
}
|
|
33
|
-
return target;
|
|
34
|
-
};
|
|
35
|
-
var __export = (target, all) => {
|
|
36
|
-
for (var name in all)
|
|
37
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
38
|
-
};
|
|
39
|
-
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
40
|
-
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
41
|
-
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
42
|
-
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
43
|
-
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
44
|
-
var __async = (__this, __arguments, generator) => {
|
|
45
|
-
return new Promise((resolve, reject) => {
|
|
46
|
-
var fulfilled = (value) => {
|
|
47
|
-
try {
|
|
48
|
-
step(generator.next(value));
|
|
49
|
-
} catch (e) {
|
|
50
|
-
reject(e);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
var rejected = (value) => {
|
|
54
|
-
try {
|
|
55
|
-
step(generator.throw(value));
|
|
56
|
-
} catch (e) {
|
|
57
|
-
reject(e);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
61
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
62
|
-
});
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
// src/ParaCore.ts
|
|
66
|
-
import { Buffer as NodeBuffer } from "buffer";
|
|
1
|
+
import "./chunk-7B52C2XE.js";
|
|
2
|
+
import { ParaCore } from "./ParaCore.js";
|
|
67
3
|
import {
|
|
68
4
|
AuthMethod,
|
|
69
|
-
|
|
70
|
-
PublicKeyType,
|
|
71
|
-
WalletType as WalletType2,
|
|
72
|
-
WalletScheme as WalletScheme2,
|
|
73
|
-
extractWalletRef,
|
|
74
|
-
PasswordStatus,
|
|
75
|
-
extractAuthInfo,
|
|
76
|
-
isEmail,
|
|
77
|
-
isPhone,
|
|
78
|
-
isFarcaster,
|
|
79
|
-
isTelegram,
|
|
80
|
-
toPregenTypeAndId,
|
|
81
|
-
toPregenIds,
|
|
82
|
-
isExternalWallet
|
|
83
|
-
} from "@getpara/user-management-client";
|
|
84
|
-
import forge3 from "node-forge";
|
|
85
|
-
|
|
86
|
-
// src/cryptography/utils.ts
|
|
87
|
-
import base64url from "base64url";
|
|
88
|
-
import forge from "node-forge";
|
|
89
|
-
|
|
90
|
-
// src/utils/autobind.ts
|
|
91
|
-
function autoBind(instance) {
|
|
92
|
-
let proto = instance;
|
|
93
|
-
while (proto && proto !== Object.prototype) {
|
|
94
|
-
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
95
|
-
const value = instance[key];
|
|
96
|
-
if (typeof value === "function" && key !== "constructor") {
|
|
97
|
-
try {
|
|
98
|
-
instance[key] = value.bind(instance);
|
|
99
|
-
} catch (e) {
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
proto = Object.getPrototypeOf(proto);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// src/utils/events.ts
|
|
108
|
-
function dispatchEvent(type, data, error) {
|
|
109
|
-
typeof window !== "undefined" && !!window.dispatchEvent && window.dispatchEvent(
|
|
110
|
-
new CustomEvent(type, { detail: __spreadValues({ data }, error && { error: new Error(error) }) })
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// src/utils/formatting.ts
|
|
115
|
-
import { toBech32 } from "@cosmjs/encoding";
|
|
116
|
-
import { sha256 } from "@noble/hashes/sha256";
|
|
117
|
-
import { ripemd160 } from "@noble/hashes/ripemd160";
|
|
118
|
-
import elliptic from "elliptic";
|
|
119
|
-
var secp256k1 = new elliptic.ec("secp256k1");
|
|
120
|
-
function hexStringToBase64(hexString) {
|
|
121
|
-
if (hexString.substring(0, 2) === "0x") {
|
|
122
|
-
hexString = hexString.substring(2);
|
|
123
|
-
}
|
|
124
|
-
return Buffer.from(hexString, "hex").toString("base64");
|
|
125
|
-
}
|
|
126
|
-
function hexToSignature(hexSig) {
|
|
127
|
-
return {
|
|
128
|
-
r: `0x${hexSig.slice(2, 66)}`,
|
|
129
|
-
s: `0x${hexSig.slice(66, 130)}`,
|
|
130
|
-
v: BigInt(hexSig.slice(130, 132))
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
function hexToUint8Array(hex) {
|
|
134
|
-
if (hex.startsWith("0x")) {
|
|
135
|
-
hex = hex.slice(2);
|
|
136
|
-
}
|
|
137
|
-
return new Uint8Array(Buffer.from(hex, "hex"));
|
|
138
|
-
}
|
|
139
|
-
function hexToDecimal(hex) {
|
|
140
|
-
if (hex.startsWith("0x")) {
|
|
141
|
-
hex = hex.slice(2);
|
|
142
|
-
}
|
|
143
|
-
return `${parseInt(hex, 16)}`;
|
|
144
|
-
}
|
|
145
|
-
function decimalToHex(decimal) {
|
|
146
|
-
return `0x${parseInt(decimal).toString(16)}`;
|
|
147
|
-
}
|
|
148
|
-
function compressPubkey(pubkey) {
|
|
149
|
-
switch (pubkey.length) {
|
|
150
|
-
case 33:
|
|
151
|
-
return pubkey;
|
|
152
|
-
case 65:
|
|
153
|
-
return Uint8Array.from(secp256k1.keyFromPublic(pubkey).getPublic(true, "array"));
|
|
154
|
-
default:
|
|
155
|
-
throw new Error("Invalid pubkey length");
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
function rawSecp256k1PubkeyToRawAddress(pubkeyData) {
|
|
159
|
-
if (pubkeyData.length !== 33) {
|
|
160
|
-
throw new Error(`Invalid Secp256k1 pubkey length (compressed): ${pubkeyData.length}`);
|
|
161
|
-
}
|
|
162
|
-
return ripemd160(sha256(pubkeyData));
|
|
163
|
-
}
|
|
164
|
-
function getCosmosAddress(publicKey, prefix) {
|
|
165
|
-
const uncompressedPublicKey = new Uint8Array(
|
|
166
|
-
Buffer.from(publicKey.startsWith("0x") ? publicKey.slice(2) : publicKey, "hex")
|
|
167
|
-
);
|
|
168
|
-
const compressedPublicKey = compressPubkey(uncompressedPublicKey);
|
|
169
|
-
return toBech32(prefix, rawSecp256k1PubkeyToRawAddress(compressedPublicKey));
|
|
170
|
-
}
|
|
171
|
-
function truncateAddress(str, addressType, { prefix = addressType === "COSMOS" ? "cosmos" : void 0 } = {}) {
|
|
172
|
-
const headLength = (addressType === "COSMOS" ? prefix.length : addressType === "SOLANA" ? 0 : 2) + 4;
|
|
173
|
-
return `${str.slice(0, headLength)}...${str.slice(-4)}`;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// src/utils/json.ts
|
|
177
|
-
function jsonParse(data, validate) {
|
|
178
|
-
try {
|
|
179
|
-
const res = JSON.parse(data);
|
|
180
|
-
if (validate && !validate(res)) {
|
|
181
|
-
return void 0;
|
|
182
|
-
}
|
|
183
|
-
return res;
|
|
184
|
-
} catch (e) {
|
|
185
|
-
return void 0;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// src/constants.ts
|
|
190
|
-
var PARA_CORE_VERSION = '2.0.0-alpha.0';
|
|
191
|
-
var PREFIX = "@CAPSULE/";
|
|
192
|
-
var LOCAL_STORAGE_AUTH_INFO = `${PREFIX}authInfo`;
|
|
193
|
-
var LOCAL_STORAGE_EMAIL = `${PREFIX}e-mail`;
|
|
194
|
-
var LOCAL_STORAGE_PHONE = `${PREFIX}phone`;
|
|
195
|
-
var LOCAL_STORAGE_COUNTRY_CODE = `${PREFIX}countryCode`;
|
|
196
|
-
var LOCAL_STORAGE_FARCASTER_USERNAME = `${PREFIX}farcasterUsername`;
|
|
197
|
-
var LOCAL_STORAGE_TELEGRAM_USER_ID = `${PREFIX}telegramUserId`;
|
|
198
|
-
var LOCAL_STORAGE_USER_ID = `${PREFIX}userId`;
|
|
199
|
-
var LOCAL_STORAGE_ED25519_WALLETS = `${PREFIX}ed25519Wallets`;
|
|
200
|
-
var LOCAL_STORAGE_WALLETS = `${PREFIX}wallets`;
|
|
201
|
-
var LOCAL_STORAGE_EXTERNAL_WALLETS = `${PREFIX}externalWallets`;
|
|
202
|
-
var LOCAL_STORAGE_CURRENT_WALLET_IDS = `${PREFIX}currentWalletIds`;
|
|
203
|
-
var LOCAL_STORAGE_SESSION_COOKIE = `${PREFIX}sessionCookie`;
|
|
204
|
-
var SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR = `${PREFIX}loginEncryptionKeyPair`;
|
|
205
|
-
var POLLING_INTERVAL_MS = 2e3;
|
|
206
|
-
var SHORT_POLLING_INTERVAL_MS = 1e3;
|
|
207
|
-
var POLLING_TIMEOUT_MS = 3e5;
|
|
208
|
-
|
|
209
|
-
// src/utils/listeners.ts
|
|
210
|
-
function storageListener(e) {
|
|
211
|
-
if (!e.url.includes(window.location.origin)) {
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
if (e.key === LOCAL_STORAGE_EXTERNAL_WALLETS) {
|
|
215
|
-
this.updateExternalWalletsFromStorage();
|
|
216
|
-
}
|
|
217
|
-
if (e.key === SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR) {
|
|
218
|
-
this.updateLoginEncryptionKeyPairFromStorage();
|
|
219
|
-
}
|
|
220
|
-
if (e.key === LOCAL_STORAGE_SESSION_COOKIE) {
|
|
221
|
-
this.updateSessionCookieFromStorage();
|
|
222
|
-
}
|
|
223
|
-
if (e.key === LOCAL_STORAGE_CURRENT_WALLET_IDS) {
|
|
224
|
-
this.updateWalletIdsFromStorage();
|
|
225
|
-
}
|
|
226
|
-
if (e.key === LOCAL_STORAGE_WALLETS || e.key === LOCAL_STORAGE_ED25519_WALLETS) {
|
|
227
|
-
this.updateWalletsFromStorage();
|
|
228
|
-
}
|
|
229
|
-
if (e.key === LOCAL_STORAGE_AUTH_INFO) {
|
|
230
|
-
this.updateAuthInfoFromStorage();
|
|
231
|
-
}
|
|
232
|
-
if (e.key === LOCAL_STORAGE_USER_ID) {
|
|
233
|
-
this.updateUserIdFromStorage();
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
function setupListeners() {
|
|
237
|
-
if (typeof window !== "undefined" && window.addEventListener && window.location) {
|
|
238
|
-
window.removeEventListener("storage", storageListener.bind(this));
|
|
239
|
-
window.addEventListener("storage", storageListener.bind(this));
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// src/utils/onRamps.ts
|
|
244
|
-
function toAssetInfoArray(data) {
|
|
245
|
-
const result = [];
|
|
246
|
-
Object.keys(data).forEach((walletType) => {
|
|
247
|
-
const networks = data[walletType];
|
|
248
|
-
Object.keys(networks).forEach((network) => {
|
|
249
|
-
const assets = networks[network];
|
|
250
|
-
Object.keys(assets).forEach((asset) => {
|
|
251
|
-
const providerInfo = assets[asset];
|
|
252
|
-
result.push([walletType, network, asset, providerInfo]);
|
|
253
|
-
});
|
|
254
|
-
});
|
|
255
|
-
});
|
|
256
|
-
return result;
|
|
257
|
-
}
|
|
258
|
-
function getOnRampNetworks(data, { walletType, allowed } = {}) {
|
|
259
|
-
return [
|
|
260
|
-
...new Set(
|
|
261
|
-
toAssetInfoArray(data).filter(([type, network]) => (!walletType || type === walletType) && (!allowed || allowed.includes(network))).map(([_, network]) => network)
|
|
262
|
-
)
|
|
263
|
-
];
|
|
264
|
-
}
|
|
265
|
-
function getOnRampAssets(data, {
|
|
266
|
-
walletType,
|
|
267
|
-
network,
|
|
268
|
-
allowed
|
|
269
|
-
} = {}) {
|
|
270
|
-
return [
|
|
271
|
-
...new Set(
|
|
272
|
-
toAssetInfoArray(data).filter(
|
|
273
|
-
([t, n, a]) => (!walletType || t === walletType) && (!network || n === network) && (!Array.isArray(allowed) || allowed.includes(a))
|
|
274
|
-
).map(([, , asset]) => asset)
|
|
275
|
-
)
|
|
276
|
-
];
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
// src/utils/phone.ts
|
|
280
|
-
import parsePhoneNumberFromString from "libphonenumber-js";
|
|
281
|
-
function formatPhoneNumber(phone, countryCode, { forDisplay = false } = {}) {
|
|
282
|
-
phone = phone.toString();
|
|
283
|
-
countryCode = countryCode == null ? void 0 : countryCode.toString();
|
|
284
|
-
let sanitizedNumber, parsedNumber;
|
|
285
|
-
if (!!countryCode) {
|
|
286
|
-
sanitizedNumber = phone.replace(/\D/g, "");
|
|
287
|
-
if (/^\+\d+$/.test(countryCode)) {
|
|
288
|
-
countryCode = countryCode.slice(1);
|
|
289
|
-
}
|
|
290
|
-
parsedNumber = parsePhoneNumberFromString(sanitizedNumber, { defaultCallingCode: countryCode });
|
|
291
|
-
} else {
|
|
292
|
-
sanitizedNumber = `+${phone.replace(/\D/g, "")}`;
|
|
293
|
-
parsedNumber = parsePhoneNumberFromString(sanitizedNumber);
|
|
294
|
-
}
|
|
295
|
-
if (parsedNumber == null ? void 0 : parsedNumber.isValid()) {
|
|
296
|
-
return forDisplay ? parsedNumber.formatInternational() : parsedNumber.formatInternational().replace(/[^\d+]/g, "");
|
|
297
|
-
}
|
|
298
|
-
return null;
|
|
299
|
-
}
|
|
300
|
-
function displayPhoneNumber(phone, countryCode) {
|
|
301
|
-
return formatPhoneNumber(phone, countryCode, { forDisplay: true });
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
// src/utils/polling.ts
|
|
305
|
-
function waitUntilTrue(condition, timeoutMs, intervalMs) {
|
|
306
|
-
return __async(this, null, function* () {
|
|
307
|
-
const start = Date.now();
|
|
308
|
-
while (Date.now() - start < timeoutMs) {
|
|
309
|
-
if (yield condition()) {
|
|
310
|
-
return true;
|
|
311
|
-
}
|
|
312
|
-
yield new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
313
|
-
}
|
|
314
|
-
return false;
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
// src/utils/types.ts
|
|
319
|
-
function isServerAuthState(obj) {
|
|
320
|
-
return "stage" in obj && Object.keys(obj).length > 0;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
// src/transmission/transmissionUtils.ts
|
|
324
|
-
import { Encrypt as ECIESEncrypt, Decrypt as ECIESDecrypt } from "@celo/utils/lib/ecies.js";
|
|
325
|
-
import { Buffer as Buffer2 } from "buffer";
|
|
326
|
-
import * as eutil from "ethereumjs-util";
|
|
327
|
-
import { randomBytes } from "crypto";
|
|
328
|
-
function upload(message, userManagementClient) {
|
|
329
|
-
return __async(this, null, function* () {
|
|
330
|
-
let secret;
|
|
331
|
-
let publicKeyUint8Array;
|
|
332
|
-
while (true) {
|
|
333
|
-
try {
|
|
334
|
-
secret = randomBytes(32).toString("hex");
|
|
335
|
-
publicKeyUint8Array = eutil.privateToPublic(Buffer2.from(secret, "hex"));
|
|
336
|
-
break;
|
|
337
|
-
} catch (e) {
|
|
338
|
-
continue;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
const pubkey = Buffer2.from(publicKeyUint8Array);
|
|
342
|
-
const data = ECIESEncrypt(pubkey, Buffer2.from(message, "ucs2")).toString("base64");
|
|
343
|
-
const {
|
|
344
|
-
data: { id }
|
|
345
|
-
} = yield userManagementClient.tempTrasmissionInit(data);
|
|
346
|
-
return encodeURIComponent(id + "|" + secret);
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
|
-
function retrieve(uriEncodedMessage, userManagementClient) {
|
|
350
|
-
return __async(this, null, function* () {
|
|
351
|
-
const [id, secret] = decodeURIComponent(uriEncodedMessage).split("|");
|
|
352
|
-
const response = yield userManagementClient.tempTrasmission(id);
|
|
353
|
-
const data = response.data.message;
|
|
354
|
-
const buf = Buffer2.from(data, "base64");
|
|
355
|
-
const res = Buffer2.from(ECIESDecrypt(Buffer2.from(secret, "hex"), buf).buffer).toString("ucs2");
|
|
356
|
-
return res;
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
// src/types/config.ts
|
|
361
|
-
var Environment = /* @__PURE__ */ ((Environment2) => {
|
|
362
|
-
Environment2["DEV"] = "DEV";
|
|
363
|
-
Environment2["SANDBOX"] = "SANDBOX";
|
|
364
|
-
Environment2["BETA"] = "BETA";
|
|
365
|
-
Environment2["PROD"] = "PROD";
|
|
366
|
-
Environment2["DEVELOPMENT"] = "BETA";
|
|
367
|
-
Environment2["PRODUCTION"] = "PROD";
|
|
368
|
-
return Environment2;
|
|
369
|
-
})(Environment || {});
|
|
370
|
-
var EnabledFlow = /* @__PURE__ */ ((EnabledFlow2) => {
|
|
371
|
-
EnabledFlow2["BUY"] = "BUY";
|
|
372
|
-
EnabledFlow2["RECEIVE"] = "RECEIVE";
|
|
373
|
-
EnabledFlow2["WITHDRAW"] = "WITHDRAW";
|
|
374
|
-
return EnabledFlow2;
|
|
375
|
-
})(EnabledFlow || {});
|
|
376
|
-
|
|
377
|
-
// src/types/coreApi.ts
|
|
378
|
-
var PARA_CORE_METHODS = [
|
|
379
|
-
"signUpOrLogIn",
|
|
380
|
-
"verifyNewAccount",
|
|
381
|
-
"waitForLogin",
|
|
382
|
-
"waitForSignup",
|
|
383
|
-
"waitForWalletCreation",
|
|
384
|
-
"verifyOAuth",
|
|
385
|
-
"verifyFarcaster",
|
|
386
|
-
"verifyTelegram",
|
|
387
|
-
"resendVerificationCode",
|
|
388
|
-
"loginExternalWallet",
|
|
389
|
-
"verifyExternalWallet",
|
|
390
|
-
"setup2fa",
|
|
391
|
-
"enable2fa",
|
|
392
|
-
"verify2fa",
|
|
393
|
-
"logout",
|
|
394
|
-
"clearStorage",
|
|
395
|
-
"isSessionActive",
|
|
396
|
-
"isFullyLoggedIn",
|
|
397
|
-
"refreshSession",
|
|
398
|
-
"keepSessionAlive",
|
|
399
|
-
"exportSession",
|
|
400
|
-
"importSession",
|
|
401
|
-
"getVerificationToken",
|
|
402
|
-
"fetchWallets",
|
|
403
|
-
"createWallet",
|
|
404
|
-
"createWalletPerType",
|
|
405
|
-
"getPregenWallets",
|
|
406
|
-
"hasPregenWallet",
|
|
407
|
-
"updatePregenWalletIdentifier",
|
|
408
|
-
"createPregenWallet",
|
|
409
|
-
"createPregenWalletPerType",
|
|
410
|
-
"claimPregenWallets",
|
|
411
|
-
"distributeNewWalletShare",
|
|
412
|
-
"getUserShare",
|
|
413
|
-
"setUserShare",
|
|
414
|
-
"refreshShare",
|
|
415
|
-
"signMessage",
|
|
416
|
-
"signTransaction",
|
|
417
|
-
"initiateOnRampTransaction"
|
|
418
|
-
];
|
|
419
|
-
|
|
420
|
-
// src/types/wallet.ts
|
|
421
|
-
var PregenIdentifierType = /* @__PURE__ */ ((PregenIdentifierType2) => {
|
|
422
|
-
PregenIdentifierType2["EMAIL"] = "EMAIL";
|
|
423
|
-
PregenIdentifierType2["PHONE"] = "PHONE";
|
|
424
|
-
return PregenIdentifierType2;
|
|
425
|
-
})(PregenIdentifierType || {});
|
|
426
|
-
|
|
427
|
-
// src/types/onRamps.ts
|
|
428
|
-
var OnRampMethod = /* @__PURE__ */ ((OnRampMethod2) => {
|
|
429
|
-
OnRampMethod2["ACH"] = "ACH";
|
|
430
|
-
OnRampMethod2["DEBIT"] = "Debit";
|
|
431
|
-
OnRampMethod2["CREDIT"] = "Credit";
|
|
432
|
-
OnRampMethod2["APPLE_PAY"] = "Apple Pay";
|
|
433
|
-
return OnRampMethod2;
|
|
434
|
-
})(OnRampMethod || {});
|
|
435
|
-
|
|
436
|
-
// src/types/popup.ts
|
|
437
|
-
var PopupType = /* @__PURE__ */ ((PopupType2) => {
|
|
438
|
-
PopupType2["SIGN_TRANSACTION_REVIEW"] = "SIGN_TRANSACTION_REVIEW";
|
|
439
|
-
PopupType2["SIGN_MESSAGE_REVIEW"] = "SIGN_MESSAGE_REVIEW";
|
|
440
|
-
PopupType2["LOGIN_PASSKEY"] = "LOGIN_PASSKEY";
|
|
441
|
-
PopupType2["CREATE_PASSKEY"] = "CREATE_PASSKEY";
|
|
442
|
-
PopupType2["OAUTH"] = "OAUTH";
|
|
443
|
-
PopupType2["ON_RAMP_TRANSACTION"] = "ON_RAMP_TRANSACTION";
|
|
444
|
-
return PopupType2;
|
|
445
|
-
})(PopupType || {});
|
|
446
|
-
|
|
447
|
-
// src/types/recovery.ts
|
|
448
|
-
var RecoveryStatus = /* @__PURE__ */ ((RecoveryStatus2) => {
|
|
449
|
-
RecoveryStatus2["INITIATED"] = "INITIATED";
|
|
450
|
-
RecoveryStatus2["READY"] = "READY";
|
|
451
|
-
RecoveryStatus2["EXPIRED"] = "EXPIRED";
|
|
452
|
-
RecoveryStatus2["FINISHED"] = "FINISHED";
|
|
453
|
-
RecoveryStatus2["CANCELLED"] = "CANCELLED";
|
|
454
|
-
return RecoveryStatus2;
|
|
455
|
-
})(RecoveryStatus || {});
|
|
456
|
-
|
|
457
|
-
// src/types/events.ts
|
|
458
|
-
var EVENT_PREFIX = "para";
|
|
459
|
-
var ParaEvent = ((ParaEvent2) => {
|
|
460
|
-
ParaEvent2["LOGIN_EVENT"] = `${EVENT_PREFIX}Login`;
|
|
461
|
-
ParaEvent2["ACCOUNT_CREATION_EVENT"] = `${EVENT_PREFIX}AccountCreation`;
|
|
462
|
-
ParaEvent2["ACCOUNT_SETUP_EVENT"] = `${EVENT_PREFIX}AccountSetup`;
|
|
463
|
-
ParaEvent2["LOGOUT_EVENT"] = `${EVENT_PREFIX}Logout`;
|
|
464
|
-
ParaEvent2["SIGN_MESSAGE_EVENT"] = `${EVENT_PREFIX}SignMessage`;
|
|
465
|
-
ParaEvent2["SIGN_TRANSACTION_EVENT"] = `${EVENT_PREFIX}SignTransaction`;
|
|
466
|
-
ParaEvent2["EXTERNAL_WALLET_CHANGE_EVENT"] = `${EVENT_PREFIX}ExternalWalletChange`;
|
|
467
|
-
ParaEvent2["WALLETS_CHANGE_EVENT"] = `${EVENT_PREFIX}WalletsChange`;
|
|
468
|
-
ParaEvent2["WALLET_CREATED"] = `${EVENT_PREFIX}WalletCreated`;
|
|
469
|
-
ParaEvent2["PREGEN_WALLET_CLAIMED"] = `${EVENT_PREFIX}PregenWalletClaimed`;
|
|
470
|
-
return ParaEvent2;
|
|
471
|
-
})(ParaEvent || {});
|
|
472
|
-
|
|
473
|
-
// src/utils/url.ts
|
|
474
|
-
function getPortalDomain(env, isE2E) {
|
|
475
|
-
if (isE2E) {
|
|
476
|
-
return `localhost`;
|
|
477
|
-
}
|
|
478
|
-
switch (env) {
|
|
479
|
-
case "DEV" /* DEV */:
|
|
480
|
-
return "localhost";
|
|
481
|
-
case "SANDBOX" /* SANDBOX */:
|
|
482
|
-
return "app.sandbox.usecapsule.com";
|
|
483
|
-
case "BETA" /* BETA */:
|
|
484
|
-
return "app.beta.usecapsule.com";
|
|
485
|
-
case "PROD" /* PROD */:
|
|
486
|
-
return "app.usecapsule.com";
|
|
487
|
-
default:
|
|
488
|
-
throw new Error(`env: ${env} not supported`);
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
function getPortalBaseURL({ env, isE2E }, useLocalIp, isForWasm) {
|
|
492
|
-
if (isE2E) {
|
|
493
|
-
if (isForWasm) {
|
|
494
|
-
return `https://app.sandbox.usecapsule.com`;
|
|
495
|
-
}
|
|
496
|
-
return `http://localhost:3003`;
|
|
497
|
-
}
|
|
498
|
-
const domain = getPortalDomain(env);
|
|
499
|
-
if (env === "DEV" /* DEV */) {
|
|
500
|
-
if (useLocalIp) {
|
|
501
|
-
return `http://127.0.0.1:3003`;
|
|
502
|
-
}
|
|
503
|
-
return `http://${domain}:3003`;
|
|
504
|
-
}
|
|
505
|
-
return `https://${domain}`;
|
|
506
|
-
}
|
|
507
|
-
function getParaConnectDomain(env) {
|
|
508
|
-
switch (env) {
|
|
509
|
-
case "DEV" /* DEV */:
|
|
510
|
-
return "localhost";
|
|
511
|
-
case "SANDBOX" /* SANDBOX */:
|
|
512
|
-
return "connect.sandbox.getpara.com";
|
|
513
|
-
case "BETA" /* BETA */:
|
|
514
|
-
return "connect.beta.getpara.com";
|
|
515
|
-
case "PROD" /* PROD */:
|
|
516
|
-
return "connect.getpara.com";
|
|
517
|
-
default:
|
|
518
|
-
throw new Error(`env: ${env} not supported`);
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
function getParaConnectBaseUrl({ env }, useLocalIp) {
|
|
522
|
-
const domain = getParaConnectDomain(env);
|
|
523
|
-
if (env === "DEV" /* DEV */) {
|
|
524
|
-
if (useLocalIp) {
|
|
525
|
-
return `http://127.0.0.1:3008`;
|
|
526
|
-
}
|
|
527
|
-
return `http://${domain}:3008`;
|
|
528
|
-
}
|
|
529
|
-
return `https://${domain}`;
|
|
530
|
-
}
|
|
531
|
-
function constructUrl({
|
|
532
|
-
base,
|
|
533
|
-
path,
|
|
534
|
-
params = {}
|
|
535
|
-
}) {
|
|
536
|
-
const url = new URL(path, base);
|
|
537
|
-
Object.entries(params).forEach(([key, value]) => {
|
|
538
|
-
if (!!value && value !== "undefined" && value !== "null") url.searchParams.set(key, value.toString());
|
|
539
|
-
});
|
|
540
|
-
return url.toString();
|
|
541
|
-
}
|
|
542
|
-
function shortenUrl(ctx, url) {
|
|
543
|
-
return __async(this, null, function* () {
|
|
544
|
-
const compressedUrl = yield upload(url, ctx.client);
|
|
545
|
-
return constructUrl({
|
|
546
|
-
base: getPortalBaseURL(ctx),
|
|
547
|
-
path: `/short/${compressedUrl}`
|
|
548
|
-
});
|
|
549
|
-
});
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
// src/utils/wallet.ts
|
|
553
|
-
import {
|
|
554
|
-
WalletScheme,
|
|
555
|
-
WalletType
|
|
556
|
-
} from "@getpara/user-management-client";
|
|
557
|
-
var WalletSchemeTypeMap = {
|
|
558
|
-
[WalletScheme.DKLS]: {
|
|
559
|
-
[WalletType.EVM]: true,
|
|
560
|
-
[WalletType.COSMOS]: true
|
|
561
|
-
},
|
|
562
|
-
[WalletScheme.CGGMP]: {
|
|
563
|
-
[WalletType.EVM]: true,
|
|
564
|
-
[WalletType.COSMOS]: true
|
|
565
|
-
},
|
|
566
|
-
[WalletScheme.ED25519]: {
|
|
567
|
-
[WalletType.SOLANA]: true
|
|
568
|
-
}
|
|
569
|
-
};
|
|
570
|
-
function isPregenIdentifierMatch(a, b, type) {
|
|
571
|
-
if (!a || !b) {
|
|
572
|
-
return false;
|
|
573
|
-
}
|
|
574
|
-
switch (type) {
|
|
575
|
-
case "EMAIL":
|
|
576
|
-
return a.toLowerCase() === b.toLowerCase();
|
|
577
|
-
case "PHONE":
|
|
578
|
-
return formatPhoneNumber(a) === formatPhoneNumber(b);
|
|
579
|
-
case "CUSTOM_ID":
|
|
580
|
-
return a === b;
|
|
581
|
-
default:
|
|
582
|
-
return a.replace(/^@/g, "").toLowerCase() === b.replace(/^@/g, "").toLowerCase();
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
function isWalletSupported(types, wallet) {
|
|
586
|
-
return types.some((walletType) => {
|
|
587
|
-
var _a;
|
|
588
|
-
return !!((_a = WalletSchemeTypeMap[wallet == null ? void 0 : wallet.scheme]) == null ? void 0 : _a[walletType]);
|
|
589
|
-
});
|
|
590
|
-
}
|
|
591
|
-
function getSchemes(types) {
|
|
592
|
-
return Object.keys(WalletSchemeTypeMap).filter((scheme) => {
|
|
593
|
-
if (scheme === WalletScheme.CGGMP) {
|
|
594
|
-
return false;
|
|
595
|
-
}
|
|
596
|
-
return (Array.isArray(types) ? types : Object.keys(types)).some((type) => WalletSchemeTypeMap[scheme][type]);
|
|
597
|
-
});
|
|
598
|
-
}
|
|
599
|
-
function getWalletTypes(schemes) {
|
|
600
|
-
return [
|
|
601
|
-
...new Set(
|
|
602
|
-
schemes.reduce((acc, scheme) => {
|
|
603
|
-
return [...acc, ...Object.keys(WalletSchemeTypeMap[scheme]).filter((type) => WalletSchemeTypeMap[scheme][type])];
|
|
604
|
-
}, [])
|
|
605
|
-
)
|
|
606
|
-
];
|
|
607
|
-
}
|
|
608
|
-
function getEquivalentTypes(types) {
|
|
609
|
-
return getWalletTypes(getSchemes((Array.isArray(types) ? types : [types]).map((t) => WalletType[t])));
|
|
610
|
-
}
|
|
611
|
-
function entityToWallet(w) {
|
|
612
|
-
return __spreadProps(__spreadValues({}, w), {
|
|
613
|
-
scheme: w.scheme,
|
|
614
|
-
type: w.type,
|
|
615
|
-
pregenIdentifierType: w.pregenIdentifierType
|
|
616
|
-
});
|
|
617
|
-
}
|
|
618
|
-
function migrateWallet(obj) {
|
|
619
|
-
if (["USER", "PREGEN"].includes(obj.type)) {
|
|
620
|
-
obj.isPregen = obj.type === "PREGEN";
|
|
621
|
-
obj.type = obj.scheme === WalletScheme.ED25519 ? WalletType.SOLANA : WalletType.EVM;
|
|
622
|
-
}
|
|
623
|
-
if (!!obj.scheme && !obj.type) {
|
|
624
|
-
obj.type = obj.scheme === WalletScheme.ED25519 ? WalletType.SOLANA : WalletType.EVM;
|
|
625
|
-
}
|
|
626
|
-
return obj;
|
|
627
|
-
}
|
|
628
|
-
function supportedWalletTypesEq(a, b) {
|
|
629
|
-
return a.length === b.length && a.every(({ type, optional }, index) => b[index].type === type && b[index].optional === optional);
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
// src/cryptography/utils.ts
|
|
633
|
-
var rsa = forge.pki.rsa;
|
|
634
|
-
var RSA_ENCRYPTION_SCHEME = "RSA-OAEP";
|
|
635
|
-
var CONSTANT_IV = "794241bc819a125a7b78ea313decc0bc";
|
|
636
|
-
var CONSTANT_IV_AES = new Uint8Array([23, 66, 157, 146, 179, 158, 117, 120, 184, 73, 123, 81]);
|
|
637
|
-
function getSHA256HashHex(str) {
|
|
638
|
-
const md = forge.md.sha256.create();
|
|
639
|
-
md.update(str);
|
|
640
|
-
return md.digest().toHex();
|
|
641
|
-
}
|
|
642
|
-
function getPublicKeyHex(keyPair) {
|
|
643
|
-
const pem = forge.pki.publicKeyToRSAPublicKeyPem(keyPair.publicKey);
|
|
644
|
-
return Buffer.from(pem, "utf-8").toString("hex");
|
|
645
|
-
}
|
|
646
|
-
function publicKeyFromHex(publicKeyHex) {
|
|
647
|
-
const pem = publicKeyHexToPem(publicKeyHex);
|
|
648
|
-
return forge.pki.publicKeyFromPem(pem);
|
|
649
|
-
}
|
|
650
|
-
function publicKeyHexToPem(publicKeyHex) {
|
|
651
|
-
return Buffer.from(publicKeyHex, "hex").toString("utf-8");
|
|
652
|
-
}
|
|
653
|
-
function encodePrivateKeyToPemHex(keyPair) {
|
|
654
|
-
const pem = forge.pki.privateKeyToPem(keyPair.privateKey);
|
|
655
|
-
return Buffer.from(pem, "utf-8").toString("hex");
|
|
656
|
-
}
|
|
657
|
-
function decodePrivateKeyPemHex(privateKeyPemHex) {
|
|
658
|
-
const pem = Buffer.from(privateKeyPemHex, "hex").toString("utf-8");
|
|
659
|
-
return forge.pki.privateKeyFromPem(pem);
|
|
660
|
-
}
|
|
661
|
-
function encryptPrivateKey(keyPair, key) {
|
|
662
|
-
return __async(this, null, function* () {
|
|
663
|
-
const privateKeyPemHex = encodePrivateKeyToPemHex(keyPair);
|
|
664
|
-
const cryptoKey = yield window.crypto.subtle.importKey(
|
|
665
|
-
"raw",
|
|
666
|
-
Buffer.from(key, "base64"),
|
|
667
|
-
{
|
|
668
|
-
name: "AES-GCM",
|
|
669
|
-
length: 256
|
|
670
|
-
},
|
|
671
|
-
true,
|
|
672
|
-
["encrypt", "decrypt"]
|
|
673
|
-
);
|
|
674
|
-
const encodedPlaintext = new TextEncoder().encode(privateKeyPemHex);
|
|
675
|
-
const ciphertext = yield window.crypto.subtle.encrypt(
|
|
676
|
-
{ name: "AES-GCM", iv: CONSTANT_IV_AES },
|
|
677
|
-
cryptoKey,
|
|
678
|
-
encodedPlaintext
|
|
679
|
-
);
|
|
680
|
-
return Buffer.from(ciphertext).toString("base64");
|
|
681
|
-
});
|
|
682
|
-
}
|
|
683
|
-
function decryptPrivateKey(encryptedPrivateKeyPemHex, key) {
|
|
684
|
-
return __async(this, null, function* () {
|
|
685
|
-
const secretKey = yield crypto.subtle.importKey(
|
|
686
|
-
"raw",
|
|
687
|
-
Buffer.from(key, "base64"),
|
|
688
|
-
{
|
|
689
|
-
name: "AES-GCM",
|
|
690
|
-
length: 256
|
|
691
|
-
},
|
|
692
|
-
true,
|
|
693
|
-
["encrypt", "decrypt"]
|
|
694
|
-
);
|
|
695
|
-
const cleartext = yield crypto.subtle.decrypt(
|
|
696
|
-
{ name: "AES-GCM", iv: CONSTANT_IV_AES },
|
|
697
|
-
secretKey,
|
|
698
|
-
Buffer.from(encryptedPrivateKeyPemHex, "base64")
|
|
699
|
-
);
|
|
700
|
-
const privateKeyPemHex = new TextDecoder().decode(cleartext);
|
|
701
|
-
const privateKey = decodePrivateKeyPemHex(privateKeyPemHex);
|
|
702
|
-
return privateKey;
|
|
703
|
-
});
|
|
704
|
-
}
|
|
705
|
-
function getAsymmetricKeyPair(ctx, seedValue) {
|
|
706
|
-
return __async(this, null, function* () {
|
|
707
|
-
const prng = forge.random.createInstance();
|
|
708
|
-
if (seedValue) {
|
|
709
|
-
prng.seedFileSync = (_n) => seedValue;
|
|
710
|
-
prng.seedFile = (_n, cb) => {
|
|
711
|
-
cb(null, seedValue);
|
|
712
|
-
};
|
|
713
|
-
}
|
|
714
|
-
const options = {
|
|
715
|
-
bits: 2048,
|
|
716
|
-
e: 65537,
|
|
717
|
-
prng
|
|
718
|
-
};
|
|
719
|
-
if (!ctx.disableWorkers) {
|
|
720
|
-
options.workLoad = 100;
|
|
721
|
-
options.workers = seedValue ? 1 : -1;
|
|
722
|
-
const workerRes = yield fetch(`${getPortalBaseURL(ctx)}/static/js/prime.worker.min.js`);
|
|
723
|
-
const workerBlob = new Blob([yield workerRes.text()], { type: "application/javascript" });
|
|
724
|
-
options.workerScript = URL.createObjectURL(workerBlob);
|
|
725
|
-
}
|
|
726
|
-
return new Promise(
|
|
727
|
-
(resolve, reject) => rsa.generateKeyPair(options, (err, keypair) => {
|
|
728
|
-
if (err) {
|
|
729
|
-
reject(err);
|
|
730
|
-
}
|
|
731
|
-
resolve(keypair);
|
|
732
|
-
})
|
|
733
|
-
);
|
|
734
|
-
});
|
|
735
|
-
}
|
|
736
|
-
function getPublicKeyFromSignature(ctx, userHandle) {
|
|
737
|
-
return __async(this, null, function* () {
|
|
738
|
-
const encodedUserHandle = base64url.encode(userHandle);
|
|
739
|
-
const keyPair = yield getAsymmetricKeyPair(ctx, encodedUserHandle);
|
|
740
|
-
return getPublicKeyHex(keyPair);
|
|
741
|
-
});
|
|
742
|
-
}
|
|
743
|
-
function symmetricKeyEncryptMessage(message) {
|
|
744
|
-
const key = forge.random.getBytesSync(16);
|
|
745
|
-
const cipher = forge.cipher.createCipher("AES-CBC", key);
|
|
746
|
-
cipher.start({ iv: CONSTANT_IV });
|
|
747
|
-
cipher.update(forge.util.createBuffer(message));
|
|
748
|
-
cipher.finish();
|
|
749
|
-
const encryptedMessageHex = cipher.output.toHex();
|
|
750
|
-
return { key, encryptedMessageHex };
|
|
751
|
-
}
|
|
752
|
-
function decipherEncryptedMessageHex(key, encryptedMessageHex) {
|
|
753
|
-
const decipher = forge.cipher.createDecipher("AES-CBC", key);
|
|
754
|
-
decipher.start({ iv: CONSTANT_IV });
|
|
755
|
-
decipher.update(forge.util.createBuffer(forge.util.hexToBytes(encryptedMessageHex)));
|
|
756
|
-
decipher.finish();
|
|
757
|
-
return decipher.output.toString();
|
|
758
|
-
}
|
|
759
|
-
function decryptWithKeyPair(keyPair, encryptedMessageHex, encryptedKeyHex) {
|
|
760
|
-
const encryptedKey = Buffer.from(encryptedKeyHex, "hex").toString("utf-8");
|
|
761
|
-
const key = keyPair.privateKey.decrypt(encryptedKey, RSA_ENCRYPTION_SCHEME);
|
|
762
|
-
return decipherEncryptedMessageHex(key, encryptedMessageHex);
|
|
763
|
-
}
|
|
764
|
-
function decryptWithPrivateKey(privateKey, encryptedMessageHex, encryptedKeyHex) {
|
|
765
|
-
const encryptedKey = Buffer.from(encryptedKeyHex, "hex").toString("utf-8");
|
|
766
|
-
const key = privateKey.decrypt(encryptedKey, RSA_ENCRYPTION_SCHEME);
|
|
767
|
-
return decipherEncryptedMessageHex(key, encryptedMessageHex);
|
|
768
|
-
}
|
|
769
|
-
function decryptWithDerivedPrivateKey(_0, _1) {
|
|
770
|
-
return __async(this, arguments, function* (ctx, {
|
|
771
|
-
seedValue,
|
|
772
|
-
encryptedMessageHex,
|
|
773
|
-
encryptedKeyHex
|
|
774
|
-
}) {
|
|
775
|
-
const keyPair = yield getAsymmetricKeyPair(ctx, seedValue);
|
|
776
|
-
return decryptWithPrivateKey(keyPair.privateKey, encryptedMessageHex, encryptedKeyHex);
|
|
777
|
-
});
|
|
778
|
-
}
|
|
779
|
-
function getDerivedPrivateKeyAndDecrypt(ctx, seedValue, encryptedShares) {
|
|
780
|
-
return __async(this, null, function* () {
|
|
781
|
-
return Promise.all(
|
|
782
|
-
encryptedShares.map((share) => __async(this, null, function* () {
|
|
783
|
-
return {
|
|
784
|
-
walletId: share.walletId,
|
|
785
|
-
walletScheme: share.walletScheme,
|
|
786
|
-
partnerId: share.partnerId,
|
|
787
|
-
signer: yield decryptWithDerivedPrivateKey(ctx, {
|
|
788
|
-
seedValue,
|
|
789
|
-
encryptedMessageHex: share.encryptedShare,
|
|
790
|
-
encryptedKeyHex: share.encryptedKey
|
|
791
|
-
}),
|
|
792
|
-
protocolId: share.protocolId
|
|
793
|
-
};
|
|
794
|
-
}))
|
|
795
|
-
);
|
|
796
|
-
});
|
|
797
|
-
}
|
|
798
|
-
function decryptPrivateKeyAndDecryptShare(encryptionKey, encryptedShares, encryptedPrivateKey) {
|
|
799
|
-
return __async(this, null, function* () {
|
|
800
|
-
let privateKey;
|
|
801
|
-
try {
|
|
802
|
-
privateKey = yield decryptPrivateKey(encryptedPrivateKey, encryptionKey);
|
|
803
|
-
} catch (e) {
|
|
804
|
-
}
|
|
805
|
-
try {
|
|
806
|
-
privateKey = yield decryptPrivateKeyWithPassword(encryptedPrivateKey, encryptionKey);
|
|
807
|
-
} catch (e) {
|
|
808
|
-
}
|
|
809
|
-
if (!privateKey) {
|
|
810
|
-
throw new Error("Could not decrypt private key");
|
|
811
|
-
}
|
|
812
|
-
return encryptedShares.map((share) => ({
|
|
813
|
-
walletId: share.walletId,
|
|
814
|
-
walletScheme: share.walletScheme,
|
|
815
|
-
partnerId: share.partnerId,
|
|
816
|
-
signer: decryptWithPrivateKey(privateKey, share.encryptedShare, share.encryptedKey),
|
|
817
|
-
protocolId: share.protocolId
|
|
818
|
-
}));
|
|
819
|
-
});
|
|
820
|
-
}
|
|
821
|
-
function encryptWithDerivedPublicKey(publicKeyHex, message) {
|
|
822
|
-
const { key, encryptedMessageHex } = symmetricKeyEncryptMessage(message);
|
|
823
|
-
const publicKeyPem = publicKeyHexToPem(publicKeyHex);
|
|
824
|
-
const publicKey = forge.pki.publicKeyFromPem(publicKeyPem);
|
|
825
|
-
const encryptedKey = publicKey.encrypt(key, RSA_ENCRYPTION_SCHEME);
|
|
826
|
-
const encryptedKeyHex = Buffer.from(encryptedKey, "utf-8").toString("hex");
|
|
827
|
-
return { encryptedMessageHex, encryptedKeyHex };
|
|
828
|
-
}
|
|
829
|
-
function hashPasswordWithSalt(password) {
|
|
830
|
-
const salt = generateSalt();
|
|
831
|
-
const saltedPassword = salt + password;
|
|
832
|
-
const hash = getSHA256HashHex(saltedPassword);
|
|
833
|
-
return { salt, hash };
|
|
834
|
-
}
|
|
835
|
-
function generateSalt(length = 16) {
|
|
836
|
-
return forge.util.bytesToHex(forge.random.getBytesSync(length));
|
|
837
|
-
}
|
|
838
|
-
function deriveCryptoKeyFromPassword(hashedPassword) {
|
|
839
|
-
return __async(this, null, function* () {
|
|
840
|
-
const keyBuffer = Buffer.from(hashedPassword, "hex");
|
|
841
|
-
return yield window.crypto.subtle.importKey(
|
|
842
|
-
"raw",
|
|
843
|
-
keyBuffer,
|
|
844
|
-
{
|
|
845
|
-
name: "AES-GCM",
|
|
846
|
-
length: 256
|
|
847
|
-
},
|
|
848
|
-
true,
|
|
849
|
-
["encrypt", "decrypt"]
|
|
850
|
-
);
|
|
851
|
-
});
|
|
852
|
-
}
|
|
853
|
-
function encryptPrivateKeyWithPassword(keyPair, hashedPassword) {
|
|
854
|
-
return __async(this, null, function* () {
|
|
855
|
-
const cryptoKey = yield deriveCryptoKeyFromPassword(hashedPassword);
|
|
856
|
-
const privateKeyPemHex = encodePrivateKeyToPemHex(keyPair);
|
|
857
|
-
const encodedPlaintext = new TextEncoder().encode(privateKeyPemHex);
|
|
858
|
-
const ciphertext = yield window.crypto.subtle.encrypt(
|
|
859
|
-
{ name: "AES-GCM", iv: CONSTANT_IV_AES },
|
|
860
|
-
cryptoKey,
|
|
861
|
-
encodedPlaintext
|
|
862
|
-
);
|
|
863
|
-
return Buffer.from(ciphertext).toString("base64");
|
|
864
|
-
});
|
|
865
|
-
}
|
|
866
|
-
function decryptPrivateKeyWithPassword(encryptedPrivateKeyPemHex, hashedPassword) {
|
|
867
|
-
return __async(this, null, function* () {
|
|
868
|
-
const secretKey = yield crypto.subtle.importKey(
|
|
869
|
-
"raw",
|
|
870
|
-
Buffer.from(hashedPassword, "hex"),
|
|
871
|
-
{
|
|
872
|
-
name: "AES-GCM",
|
|
873
|
-
length: 256
|
|
874
|
-
},
|
|
875
|
-
true,
|
|
876
|
-
["encrypt", "decrypt"]
|
|
877
|
-
);
|
|
878
|
-
const cleartext = yield crypto.subtle.decrypt(
|
|
879
|
-
{ name: "AES-GCM", iv: CONSTANT_IV_AES },
|
|
880
|
-
secretKey,
|
|
881
|
-
Buffer.from(encryptedPrivateKeyPemHex, "base64")
|
|
882
|
-
);
|
|
883
|
-
const privateKeyPemHex = new TextDecoder().decode(cleartext);
|
|
884
|
-
const privateKey = decodePrivateKeyPemHex(privateKeyPemHex);
|
|
885
|
-
return privateKey;
|
|
886
|
-
});
|
|
887
|
-
}
|
|
888
|
-
|
|
889
|
-
// src/external/userManagementClient.ts
|
|
890
|
-
import Client from "@getpara/user-management-client";
|
|
891
|
-
function getBaseOAuthUrl(env) {
|
|
892
|
-
switch (env) {
|
|
893
|
-
case "DEV" /* DEV */:
|
|
894
|
-
return "http://localhost:8080/";
|
|
895
|
-
case "SANDBOX" /* SANDBOX */:
|
|
896
|
-
return "https://api.sandbox.usecapsule.com/";
|
|
897
|
-
case "BETA" /* BETA */:
|
|
898
|
-
return "https://api.beta.usecapsule.com/";
|
|
899
|
-
case "PROD" /* PROD */:
|
|
900
|
-
return "https://api.usecapsule.com/";
|
|
901
|
-
default:
|
|
902
|
-
throw new Error(`unsupported env: ${env}`);
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
function getBaseUrl(env) {
|
|
906
|
-
switch (env) {
|
|
907
|
-
case "DEV" /* DEV */:
|
|
908
|
-
return "http://localhost:8080/";
|
|
909
|
-
case "SANDBOX" /* SANDBOX */:
|
|
910
|
-
return "https://api.sandbox.getpara.com/";
|
|
911
|
-
case "BETA" /* BETA */:
|
|
912
|
-
return "https://api.beta.getpara.com/";
|
|
913
|
-
case "PROD" /* PROD */:
|
|
914
|
-
return "https://api.getpara.com/";
|
|
915
|
-
default:
|
|
916
|
-
throw new Error(`unsupported env: ${env}`);
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
function getBaseMPCNetworkUrl(env, useWebsocket) {
|
|
920
|
-
const prefix = useWebsocket ? "ws" : "http";
|
|
921
|
-
switch (env) {
|
|
922
|
-
case "DEV" /* DEV */:
|
|
923
|
-
return `${prefix}://localhost:3000`;
|
|
924
|
-
case "SANDBOX" /* SANDBOX */:
|
|
925
|
-
return `${prefix}s://mpc-network.sandbox.getpara.com`;
|
|
926
|
-
case "BETA" /* BETA */:
|
|
927
|
-
return `${prefix}s://mpc-network.beta.getpara.com`;
|
|
928
|
-
case "PROD" /* PROD */:
|
|
929
|
-
return `${prefix}s://mpc-network.prod.getpara.com`;
|
|
930
|
-
default:
|
|
931
|
-
throw new Error(`unsupported env: ${env}`);
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
function initClient({
|
|
935
|
-
env,
|
|
936
|
-
version,
|
|
937
|
-
apiKey,
|
|
938
|
-
partnerId,
|
|
939
|
-
useFetchAdapter = false,
|
|
940
|
-
retrieveSessionCookie,
|
|
941
|
-
persistSessionCookie
|
|
942
|
-
}) {
|
|
943
|
-
return new Client({
|
|
944
|
-
userManagementHost: getBaseUrl(env),
|
|
945
|
-
version: ["DEV" /* DEV */, "SANDBOX" /* SANDBOX */].includes(env) ? "dev-v2" : version,
|
|
946
|
-
apiKey,
|
|
947
|
-
partnerId,
|
|
948
|
-
opts: { useFetchAdapter },
|
|
949
|
-
retrieveSessionCookie,
|
|
950
|
-
persistSessionCookie
|
|
951
|
-
});
|
|
952
|
-
}
|
|
953
|
-
|
|
954
|
-
// src/external/mpcComputationClient.ts
|
|
955
|
-
var mpcComputationClient_exports = {};
|
|
956
|
-
__export(mpcComputationClient_exports, {
|
|
957
|
-
initClient: () => initClient2
|
|
958
|
-
});
|
|
959
|
-
import axios from "axios";
|
|
960
|
-
function initClient2(baseURL, useAdapter) {
|
|
961
|
-
const client = axios.create({ baseURL });
|
|
962
|
-
if (useAdapter) {
|
|
963
|
-
client.defaults.adapter = function(config) {
|
|
964
|
-
return fetch(config.baseURL + config.url, {
|
|
965
|
-
method: config.method,
|
|
966
|
-
headers: config.headers,
|
|
967
|
-
body: config.data,
|
|
968
|
-
credentials: config.withCredentials ? "include" : void 0
|
|
969
|
-
}).then(
|
|
970
|
-
(response) => response.text().then((text) => ({
|
|
971
|
-
data: text,
|
|
972
|
-
status: response.status,
|
|
973
|
-
statusText: response.statusText,
|
|
974
|
-
headers: response.headers,
|
|
975
|
-
config,
|
|
976
|
-
request: fetch
|
|
977
|
-
}))
|
|
978
|
-
).catch(function(reason) {
|
|
979
|
-
throw reason;
|
|
980
|
-
});
|
|
981
|
-
};
|
|
982
|
-
}
|
|
983
|
-
return client;
|
|
984
|
-
}
|
|
985
|
-
|
|
986
|
-
// src/shares/shareDistribution.ts
|
|
987
|
-
import { EncryptorType as EncryptorType2, KeyShareType as KeyShareType2 } from "@getpara/user-management-client";
|
|
988
|
-
|
|
989
|
-
// src/shares/recovery.ts
|
|
990
|
-
import { EncryptorType, KeyShareType } from "@getpara/user-management-client";
|
|
991
|
-
|
|
992
|
-
// src/shares/KeyContainer.ts
|
|
993
|
-
import { Encrypt as ECIESEncrypt2, Decrypt as ECIESDecrypt2 } from "@celo/utils/lib/ecies.js";
|
|
994
|
-
import * as eutil2 from "ethereumjs-util";
|
|
995
|
-
import * as forge2 from "node-forge";
|
|
996
|
-
var KeyContainer = class _KeyContainer {
|
|
997
|
-
constructor(walletId, keyshare, address) {
|
|
998
|
-
this.walletId = walletId;
|
|
999
|
-
this.keyshare = keyshare;
|
|
1000
|
-
this.address = address;
|
|
1001
|
-
this.backupDecryptionKey = Buffer.from(forge2.random.getBytesSync(32), "binary").toString("hex");
|
|
1002
|
-
}
|
|
1003
|
-
static buildFrom(serializedContainer) {
|
|
1004
|
-
try {
|
|
1005
|
-
const parsedObject = JSON.parse(serializedContainer);
|
|
1006
|
-
return Object.assign(new _KeyContainer("", "", ""), parsedObject);
|
|
1007
|
-
} catch (e) {
|
|
1008
|
-
const container = new _KeyContainer("", "", "");
|
|
1009
|
-
container.backupDecryptionKey = serializedContainer.split("|")[0];
|
|
1010
|
-
return container;
|
|
1011
|
-
}
|
|
1012
|
-
}
|
|
1013
|
-
getPublicEncryptionKey() {
|
|
1014
|
-
return Buffer.from(eutil2.privateToPublic(Buffer.from(this.backupDecryptionKey, "hex")));
|
|
1015
|
-
}
|
|
1016
|
-
getPublicEncryptionKeyHex() {
|
|
1017
|
-
return this.getPublicEncryptionKey().toString("hex");
|
|
1018
|
-
}
|
|
1019
|
-
encryptForSelf(backup) {
|
|
1020
|
-
try {
|
|
1021
|
-
const pubkey = this.getPublicEncryptionKey();
|
|
1022
|
-
const data = ECIESEncrypt2(pubkey, Buffer.from(backup, "ucs2")).toString("base64");
|
|
1023
|
-
return data;
|
|
1024
|
-
} catch (error) {
|
|
1025
|
-
throw Error("Error encrypting backup");
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
|
-
static encryptWithPublicKey(publicKey, backup) {
|
|
1029
|
-
try {
|
|
1030
|
-
const data = ECIESEncrypt2(publicKey, Buffer.from(backup, "ucs2")).toString("base64");
|
|
1031
|
-
return data;
|
|
1032
|
-
} catch (error) {
|
|
1033
|
-
throw Error("Error encrypting backup");
|
|
1034
|
-
}
|
|
1035
|
-
}
|
|
1036
|
-
decrypt(encryptedBackup) {
|
|
1037
|
-
try {
|
|
1038
|
-
const buf = Buffer.from(encryptedBackup, "base64");
|
|
1039
|
-
const data = ECIESDecrypt2(Buffer.from(this.backupDecryptionKey, "hex"), buf);
|
|
1040
|
-
return Buffer.from(data.buffer).toString("ucs2");
|
|
1041
|
-
} catch (error) {
|
|
1042
|
-
throw Error("Error decrypting backup");
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
};
|
|
1046
|
-
|
|
1047
|
-
// src/shares/recovery.ts
|
|
1048
|
-
function sendRecoveryForShare(_0) {
|
|
1049
|
-
return __async(this, arguments, function* ({
|
|
1050
|
-
ctx,
|
|
1051
|
-
userId,
|
|
1052
|
-
walletId,
|
|
1053
|
-
otherEncryptedShares = [],
|
|
1054
|
-
userSigner,
|
|
1055
|
-
ignoreRedistributingBackupEncryptedShare = false,
|
|
1056
|
-
emailProps = {},
|
|
1057
|
-
forceRefresh = false
|
|
1058
|
-
}) {
|
|
1059
|
-
if (ignoreRedistributingBackupEncryptedShare) {
|
|
1060
|
-
yield ctx.client.uploadUserKeyShares(
|
|
1061
|
-
userId,
|
|
1062
|
-
otherEncryptedShares.map((share) => __spreadValues({
|
|
1063
|
-
walletId
|
|
1064
|
-
}, share))
|
|
1065
|
-
);
|
|
1066
|
-
return "";
|
|
1067
|
-
}
|
|
1068
|
-
let userBackupKeyShareOptsArr;
|
|
1069
|
-
let recoveryPrivateKeyContainer;
|
|
1070
|
-
const { recoveryPublicKeys } = yield ctx.client.getRecoveryPublicKeys(userId);
|
|
1071
|
-
if (forceRefresh || !(recoveryPublicKeys == null ? void 0 : recoveryPublicKeys.length)) {
|
|
1072
|
-
recoveryPrivateKeyContainer = new KeyContainer(walletId, "", "");
|
|
1073
|
-
const { recoveryPublicKeys: recoveryPublicKeys2 } = yield ctx.client.persistRecoveryPublicKeys(userId, [
|
|
1074
|
-
recoveryPrivateKeyContainer.getPublicEncryptionKeyHex()
|
|
1075
|
-
]);
|
|
1076
|
-
const encryptedUserBackup = recoveryPrivateKeyContainer.encryptForSelf(userSigner);
|
|
1077
|
-
userBackupKeyShareOptsArr = [
|
|
1078
|
-
{
|
|
1079
|
-
walletId,
|
|
1080
|
-
encryptedShare: encryptedUserBackup,
|
|
1081
|
-
type: KeyShareType.USER,
|
|
1082
|
-
encryptor: EncryptorType.RECOVERY,
|
|
1083
|
-
recoveryPublicKeyId: recoveryPublicKeys2[0].id
|
|
1084
|
-
}
|
|
1085
|
-
];
|
|
1086
|
-
} else {
|
|
1087
|
-
userBackupKeyShareOptsArr = recoveryPublicKeys.map((recoveryPublicKey) => {
|
|
1088
|
-
const { id: recoveryPublicKeyId, publicKey } = recoveryPublicKey;
|
|
1089
|
-
const encryptedUserBackup = KeyContainer.encryptWithPublicKey(Buffer.from(publicKey, "hex"), userSigner);
|
|
1090
|
-
return {
|
|
1091
|
-
walletId,
|
|
1092
|
-
encryptedShare: encryptedUserBackup,
|
|
1093
|
-
type: KeyShareType.USER,
|
|
1094
|
-
encryptor: EncryptorType.RECOVERY,
|
|
1095
|
-
recoveryPublicKeyId
|
|
1096
|
-
};
|
|
1097
|
-
});
|
|
1098
|
-
}
|
|
1099
|
-
yield ctx.client.uploadUserKeyShares(userId, [
|
|
1100
|
-
...otherEncryptedShares.map((share) => __spreadValues({
|
|
1101
|
-
walletId
|
|
1102
|
-
}, share)),
|
|
1103
|
-
...ignoreRedistributingBackupEncryptedShare ? [] : userBackupKeyShareOptsArr
|
|
1104
|
-
]);
|
|
1105
|
-
yield ctx.client.distributeParaShare(__spreadValues({
|
|
1106
|
-
userId,
|
|
1107
|
-
walletId,
|
|
1108
|
-
useDKLS: ctx.useDKLS
|
|
1109
|
-
}, emailProps));
|
|
1110
|
-
return recoveryPrivateKeyContainer ? JSON.stringify(recoveryPrivateKeyContainer) : "";
|
|
1111
|
-
});
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
// src/shares/shareDistribution.ts
|
|
1115
|
-
function distributeNewShare(_0) {
|
|
1116
|
-
return __async(this, arguments, function* ({
|
|
1117
|
-
ctx,
|
|
1118
|
-
userId,
|
|
1119
|
-
walletId,
|
|
1120
|
-
userShare,
|
|
1121
|
-
ignoreRedistributingBackupEncryptedShare = false,
|
|
1122
|
-
emailProps = {},
|
|
1123
|
-
partnerId,
|
|
1124
|
-
protocolId
|
|
1125
|
-
}) {
|
|
1126
|
-
const publicKeysRes = yield ctx.client.getSessionPublicKeys(userId);
|
|
1127
|
-
const biometricEncryptedShares = publicKeysRes.data.keys.map((key) => {
|
|
1128
|
-
if (!key.publicKey) {
|
|
1129
|
-
return;
|
|
1130
|
-
}
|
|
1131
|
-
const { encryptedMessageHex, encryptedKeyHex } = encryptWithDerivedPublicKey(key.sigDerivedPublicKey, userShare);
|
|
1132
|
-
return {
|
|
1133
|
-
encryptedShare: encryptedMessageHex,
|
|
1134
|
-
encryptedKey: encryptedKeyHex,
|
|
1135
|
-
type: KeyShareType2.USER,
|
|
1136
|
-
encryptor: EncryptorType2.BIOMETRICS,
|
|
1137
|
-
biometricPublicKey: key.sigDerivedPublicKey,
|
|
1138
|
-
partnerId,
|
|
1139
|
-
protocolId
|
|
1140
|
-
};
|
|
1141
|
-
}).filter(Boolean);
|
|
1142
|
-
const passwords = yield ctx.client.getPasswords({ userId });
|
|
1143
|
-
const passwordEncryptedShares = passwords.map((password) => {
|
|
1144
|
-
if (password.status === "PENDING") {
|
|
1145
|
-
return;
|
|
1146
|
-
}
|
|
1147
|
-
const { encryptedMessageHex, encryptedKeyHex } = encryptWithDerivedPublicKey(password.sigDerivedPublicKey, userShare);
|
|
1148
|
-
return {
|
|
1149
|
-
encryptedShare: encryptedMessageHex,
|
|
1150
|
-
encryptedKey: encryptedKeyHex,
|
|
1151
|
-
type: KeyShareType2.USER,
|
|
1152
|
-
encryptor: EncryptorType2.PASSWORD,
|
|
1153
|
-
passwordId: password.id,
|
|
1154
|
-
partnerId,
|
|
1155
|
-
protocolId
|
|
1156
|
-
};
|
|
1157
|
-
}).filter(Boolean);
|
|
1158
|
-
const allEncryptedShares = [...biometricEncryptedShares, ...passwordEncryptedShares];
|
|
1159
|
-
return yield sendRecoveryForShare({
|
|
1160
|
-
ctx,
|
|
1161
|
-
userId,
|
|
1162
|
-
walletId,
|
|
1163
|
-
otherEncryptedShares: allEncryptedShares,
|
|
1164
|
-
userSigner: userShare,
|
|
1165
|
-
ignoreRedistributingBackupEncryptedShare,
|
|
1166
|
-
emailProps
|
|
1167
|
-
});
|
|
1168
|
-
});
|
|
1169
|
-
}
|
|
1170
|
-
|
|
1171
|
-
// src/errors.ts
|
|
1172
|
-
var TransactionReviewError = class extends Error {
|
|
1173
|
-
constructor(transactionReviewUrl) {
|
|
1174
|
-
super("transaction review error");
|
|
1175
|
-
this.name = "TransactionReviewError";
|
|
1176
|
-
this.transactionReviewUrl = transactionReviewUrl;
|
|
1177
|
-
}
|
|
1178
|
-
};
|
|
1179
|
-
var TransactionReviewDenied = class extends Error {
|
|
1180
|
-
constructor() {
|
|
1181
|
-
super("transaction review has been denied by the user");
|
|
1182
|
-
this.name = "TransactionReviewDenied";
|
|
1183
|
-
}
|
|
1184
|
-
};
|
|
1185
|
-
var TransactionReviewTimeout = class extends Error {
|
|
1186
|
-
constructor(transactionReviewUrl, pendingTransactionId) {
|
|
1187
|
-
super("transaction review has timed out");
|
|
1188
|
-
this.name = "TransactionReviewTimeout";
|
|
1189
|
-
this.transactionReviewUrl = transactionReviewUrl;
|
|
1190
|
-
this.pendingTransactionId = pendingTransactionId;
|
|
1191
|
-
}
|
|
1192
|
-
};
|
|
1193
|
-
|
|
1194
|
-
// src/ParaCore.ts
|
|
1195
|
-
if (typeof global !== "undefined") {
|
|
1196
|
-
global.Buffer = global.Buffer || NodeBuffer;
|
|
1197
|
-
} else if (typeof window !== "undefined") {
|
|
1198
|
-
window.Buffer = window.Buffer || NodeBuffer;
|
|
1199
|
-
window.global = window.global || window;
|
|
1200
|
-
} else {
|
|
1201
|
-
self.Buffer = self.Buffer || NodeBuffer;
|
|
1202
|
-
self.global = self.global || self;
|
|
1203
|
-
}
|
|
1204
|
-
var { pki, jsbn } = forge3;
|
|
1205
|
-
var _authInfo, _partner, _ParaCore_instances, assertPartner_fn, toAuthInfo_fn, setAuthInfo_fn, getPartner_fn, prepareAuthState_fn, prepareLogin_fn, prepareLoginState_fn, prepareSignUpState_fn;
|
|
1206
|
-
var _ParaCore = class _ParaCore {
|
|
1207
|
-
/**
|
|
1208
|
-
* Constructs a new `ParaCore` instance.
|
|
1209
|
-
* @param env - `Environment` to use.
|
|
1210
|
-
* @param apiKey - API key to use.
|
|
1211
|
-
* @param opts - Additional constructor options; see `ConstructorOpts`.
|
|
1212
|
-
* @returns - A new ParaCore instance.
|
|
1213
|
-
*/
|
|
1214
|
-
constructor(env, apiKey, opts) {
|
|
1215
|
-
__privateAdd(this, _ParaCore_instances);
|
|
1216
|
-
__privateAdd(this, _authInfo);
|
|
1217
|
-
this.isNativePasskey = false;
|
|
1218
|
-
__privateAdd(this, _partner);
|
|
1219
|
-
this.isAwaitingAccountCreation = false;
|
|
1220
|
-
this.isAwaitingLogin = false;
|
|
1221
|
-
this.isAwaitingFarcaster = false;
|
|
1222
|
-
this.isAwaitingOAuth = false;
|
|
1223
|
-
/**
|
|
1224
|
-
* 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.
|
|
1225
|
-
*/
|
|
1226
|
-
this.currentWalletIds = {};
|
|
1227
|
-
/**
|
|
1228
|
-
* Wallets associated with the `ParaCore` instance.
|
|
1229
|
-
*/
|
|
1230
|
-
this.externalWallets = {};
|
|
1231
|
-
this.localStorageGetItem = (key) => {
|
|
1232
|
-
return this.platformUtils.localStorage.get(key);
|
|
1233
|
-
};
|
|
1234
|
-
this.localStorageSetItem = (key, value) => {
|
|
1235
|
-
return this.platformUtils.localStorage.set(key, value);
|
|
1236
|
-
};
|
|
1237
|
-
this.localStorageRemoveItem = (key) => {
|
|
1238
|
-
return this.platformUtils.localStorage.removeItem(key);
|
|
1239
|
-
};
|
|
1240
|
-
this.sessionStorageGetItem = (key) => {
|
|
1241
|
-
return this.platformUtils.sessionStorage.get(key);
|
|
1242
|
-
};
|
|
1243
|
-
this.sessionStorageSetItem = (key, value) => {
|
|
1244
|
-
return this.platformUtils.sessionStorage.set(key, value);
|
|
1245
|
-
};
|
|
1246
|
-
this.sessionStorageRemoveItem = (key) => {
|
|
1247
|
-
return this.platformUtils.sessionStorage.removeItem(key);
|
|
1248
|
-
};
|
|
1249
|
-
this.retrieveSessionCookie = () => {
|
|
1250
|
-
return this.sessionCookie;
|
|
1251
|
-
};
|
|
1252
|
-
/**
|
|
1253
|
-
* Remove all local storage and prefixed session storage.
|
|
1254
|
-
* @param {'local' | 'session' | 'secure' | 'all'} type - Type of storage to clear. Defaults to 'all'.
|
|
1255
|
-
*/
|
|
1256
|
-
this.clearStorage = (type = "all") => __async(this, null, function* () {
|
|
1257
|
-
const isAll = type === "all";
|
|
1258
|
-
(isAll || type === "local") && this.platformUtils.localStorage.clear(PREFIX);
|
|
1259
|
-
(isAll || type === "session") && this.platformUtils.sessionStorage.clear(PREFIX);
|
|
1260
|
-
if ((isAll || type === "secure") && this.platformUtils.secureStorage) {
|
|
1261
|
-
this.platformUtils.secureStorage.clear(PREFIX);
|
|
1262
|
-
}
|
|
1263
|
-
});
|
|
1264
|
-
this.initializeFromStorage = () => {
|
|
1265
|
-
this.updateExternalWalletsFromStorage();
|
|
1266
|
-
this.updateAuthInfoFromStorage();
|
|
1267
|
-
this.updateUserIdFromStorage();
|
|
1268
|
-
this.updateWalletsFromStorage();
|
|
1269
|
-
this.updateWalletIdsFromStorage();
|
|
1270
|
-
this.updateSessionCookieFromStorage();
|
|
1271
|
-
this.updateLoginEncryptionKeyPairFromStorage();
|
|
1272
|
-
};
|
|
1273
|
-
this.updateAuthInfoFromStorage = () => {
|
|
1274
|
-
var _a;
|
|
1275
|
-
const storageAuthInfo = this.localStorageGetItem(LOCAL_STORAGE_AUTH_INFO) || void 0;
|
|
1276
|
-
let authInfo = jsonParse(storageAuthInfo);
|
|
1277
|
-
if (!authInfo) {
|
|
1278
|
-
const authParams = {
|
|
1279
|
-
email: this.localStorageGetItem(LOCAL_STORAGE_EMAIL) || void 0,
|
|
1280
|
-
phone: this.localStorageGetItem(LOCAL_STORAGE_PHONE) || void 0,
|
|
1281
|
-
countryCode: this.localStorageGetItem(LOCAL_STORAGE_COUNTRY_CODE) || void 0,
|
|
1282
|
-
farcasterUsername: this.localStorageGetItem(LOCAL_STORAGE_FARCASTER_USERNAME) || void 0,
|
|
1283
|
-
telegramUserId: this.localStorageGetItem(LOCAL_STORAGE_TELEGRAM_USER_ID) || void 0,
|
|
1284
|
-
// Using id here since we store the bech32 address for cosmos in the address field of the wallet
|
|
1285
|
-
externalWalletAddress: ((_a = this.externalWalletWithParaAuth) == null ? void 0 : _a.id) || void 0
|
|
1286
|
-
};
|
|
1287
|
-
authInfo = __privateMethod(this, _ParaCore_instances, toAuthInfo_fn).call(this, authParams);
|
|
1288
|
-
}
|
|
1289
|
-
__privateSet(this, _authInfo, authInfo);
|
|
1290
|
-
};
|
|
1291
|
-
this.updateUserIdFromStorage = () => {
|
|
1292
|
-
this.userId = this.localStorageGetItem(LOCAL_STORAGE_USER_ID) || void 0;
|
|
1293
|
-
};
|
|
1294
|
-
this.updateWalletsFromStorage = () => __async(this, null, function* () {
|
|
1295
|
-
var _a;
|
|
1296
|
-
const _currentWalletIds = (_a = this.localStorageGetItem(LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _a : void 0;
|
|
1297
|
-
const currentWalletIds = [void 0, null, "undefined"].includes(_currentWalletIds) ? {} : (() => {
|
|
1298
|
-
const fromJson = JSON.parse(_currentWalletIds);
|
|
1299
|
-
return Array.isArray(fromJson) ? Object.keys(WalletType2).reduce((acc, type) => {
|
|
1300
|
-
const wallet = Object.values(this.wallets).find(
|
|
1301
|
-
(w) => fromJson.includes(w.id) && WalletSchemeTypeMap[w.scheme][type]
|
|
1302
|
-
);
|
|
1303
|
-
return __spreadValues(__spreadValues({}, acc), wallet && !acc[type] ? { [type]: [wallet.id] } : {});
|
|
1304
|
-
}, {}) : fromJson;
|
|
1305
|
-
})();
|
|
1306
|
-
this.setCurrentWalletIds(currentWalletIds);
|
|
1307
|
-
const stringWallets = this.platformUtils.secureStorage ? this.platformUtils.secureStorage.get(LOCAL_STORAGE_WALLETS) : this.localStorageGetItem(LOCAL_STORAGE_WALLETS);
|
|
1308
|
-
const _wallets = JSON.parse(stringWallets || "{}");
|
|
1309
|
-
const stringEd25519Wallets = this.platformUtils.secureStorage ? this.platformUtils.secureStorage.get(LOCAL_STORAGE_ED25519_WALLETS) : this.localStorageGetItem(LOCAL_STORAGE_ED25519_WALLETS);
|
|
1310
|
-
const _ed25519Wallets = JSON.parse(stringEd25519Wallets || "{}");
|
|
1311
|
-
const wallets = __spreadValues(__spreadValues({}, Object.keys(_wallets).reduce((res, key) => {
|
|
1312
|
-
return __spreadProps(__spreadValues({}, res), {
|
|
1313
|
-
[key]: migrateWallet(_wallets[key])
|
|
1314
|
-
});
|
|
1315
|
-
}, {})), Object.keys(_ed25519Wallets).reduce((res, key) => {
|
|
1316
|
-
return __spreadValues(__spreadValues({}, res), !res[key] ? { [key]: migrateWallet(_ed25519Wallets[key]) } : {});
|
|
1317
|
-
}, {}));
|
|
1318
|
-
this.setWallets(wallets);
|
|
1319
|
-
});
|
|
1320
|
-
this.updateWalletIdsFromStorage = () => {
|
|
1321
|
-
var _a;
|
|
1322
|
-
const _currentWalletIds = (_a = this.localStorageGetItem(LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _a : void 0;
|
|
1323
|
-
const currentWalletIds = [void 0, null, "undefined", "null"].includes(_currentWalletIds) ? {} : (() => {
|
|
1324
|
-
const fromJson = JSON.parse(_currentWalletIds);
|
|
1325
|
-
return Array.isArray(fromJson) ? Object.keys(WalletType2).reduce((acc, type) => {
|
|
1326
|
-
const wallet = Object.values(this.wallets).find(
|
|
1327
|
-
(w) => fromJson.includes(w.id) && WalletSchemeTypeMap[w.scheme][type]
|
|
1328
|
-
);
|
|
1329
|
-
return __spreadValues(__spreadValues({}, acc), wallet && !acc[type] ? { [type]: [wallet.id] } : {});
|
|
1330
|
-
}, {}) : fromJson;
|
|
1331
|
-
})();
|
|
1332
|
-
this.setCurrentWalletIds(currentWalletIds);
|
|
1333
|
-
if (Object.values(this.wallets).filter((w) => this.isWalletOwned(w)).length > 0 && this.currentWalletIdsArray.length === 0) {
|
|
1334
|
-
this.findWalletId(void 0, { forbidPregen: true });
|
|
1335
|
-
}
|
|
1336
|
-
};
|
|
1337
|
-
this.updateSessionCookieFromStorage = () => {
|
|
1338
|
-
this.sessionCookie = this.localStorageGetItem(LOCAL_STORAGE_SESSION_COOKIE) || this.sessionStorageGetItem(LOCAL_STORAGE_SESSION_COOKIE) || void 0;
|
|
1339
|
-
};
|
|
1340
|
-
this.updateLoginEncryptionKeyPairFromStorage = () => {
|
|
1341
|
-
const loginEncryptionKey = this.sessionStorageGetItem(SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR);
|
|
1342
|
-
if (loginEncryptionKey && loginEncryptionKey !== "undefined") {
|
|
1343
|
-
this.loginEncryptionKeyPair = this.convertEncryptionKeyPair(JSON.parse(loginEncryptionKey));
|
|
1344
|
-
}
|
|
1345
|
-
};
|
|
1346
|
-
this.updateExternalWalletsFromStorage = () => {
|
|
1347
|
-
const stringExternalWallets = this.localStorageGetItem(LOCAL_STORAGE_EXTERNAL_WALLETS);
|
|
1348
|
-
const _externalWallets = JSON.parse(stringExternalWallets || "{}");
|
|
1349
|
-
this.setExternalWallets(_externalWallets);
|
|
1350
|
-
};
|
|
1351
|
-
/**
|
|
1352
|
-
* Creates several new wallets with the desired types. If no types are provided, this method
|
|
1353
|
-
* will create one for each of the non-optional types specified in the instance's `supportedWalletTypes`
|
|
1354
|
-
* object that are not already present. This is automatically called upon account creation to ensure that
|
|
1355
|
-
* the user has a wallet of each required type.
|
|
1356
|
-
*
|
|
1357
|
-
* @deprecated alias for `createWalletPerType`
|
|
1358
|
-
**/
|
|
1359
|
-
this.createWalletPerMissingType = this.createWalletPerType;
|
|
1360
|
-
if (!apiKey) {
|
|
1361
|
-
throw new Error("A Para API key is required.");
|
|
1362
|
-
}
|
|
1363
|
-
if (!opts) opts = {};
|
|
1364
|
-
let isE2E = false;
|
|
1365
|
-
if (env === "E2E") {
|
|
1366
|
-
isE2E = true;
|
|
1367
|
-
env = "SANDBOX" /* SANDBOX */;
|
|
1368
|
-
}
|
|
1369
|
-
this.emailPrimaryColor = opts.emailPrimaryColor;
|
|
1370
|
-
this.emailTheme = opts.emailTheme;
|
|
1371
|
-
this.homepageUrl = opts.homepageUrl;
|
|
1372
|
-
this.supportUrl = opts.supportUrl;
|
|
1373
|
-
this.xUrl = opts.xUrl;
|
|
1374
|
-
this.githubUrl = opts.githubUrl;
|
|
1375
|
-
this.linkedinUrl = opts.linkedinUrl;
|
|
1376
|
-
this.portalBackgroundColor = opts.portalBackgroundColor;
|
|
1377
|
-
this.portalPrimaryButtonColor = opts.portalPrimaryButtonColor;
|
|
1378
|
-
this.portalTextColor = opts.portalTextColor;
|
|
1379
|
-
this.portalPrimaryButtonTextColor = opts.portalPrimaryButtonTextColor;
|
|
1380
|
-
this.portalTheme = opts.portalTheme;
|
|
1381
|
-
this.platformUtils = this.getPlatformUtils();
|
|
1382
|
-
this.disableProviderModal = this.platformUtils.disableProviderModal;
|
|
1383
|
-
if (opts.useStorageOverrides) {
|
|
1384
|
-
this.localStorageGetItem = opts.localStorageGetItemOverride;
|
|
1385
|
-
this.localStorageSetItem = opts.localStorageSetItemOverride;
|
|
1386
|
-
this.sessionStorageGetItem = opts.sessionStorageGetItemOverride;
|
|
1387
|
-
this.sessionStorageSetItem = opts.sessionStorageSetItemOverride;
|
|
1388
|
-
this.sessionStorageRemoveItem = opts.sessionStorageRemoveItemOverride;
|
|
1389
|
-
this.clearStorage = opts.clearStorageOverride;
|
|
1390
|
-
}
|
|
1391
|
-
if (opts.useSessionStorage) {
|
|
1392
|
-
this.localStorageGetItem = this.sessionStorageGetItem;
|
|
1393
|
-
this.localStorageSetItem = this.sessionStorageSetItem;
|
|
1394
|
-
}
|
|
1395
|
-
this.persistSessionCookie = (cookie) => {
|
|
1396
|
-
this.sessionCookie = cookie;
|
|
1397
|
-
(opts.useSessionStorage ? this.sessionStorageSetItem : this.localStorageSetItem)(
|
|
1398
|
-
LOCAL_STORAGE_SESSION_COOKIE,
|
|
1399
|
-
cookie
|
|
1400
|
-
);
|
|
1401
|
-
};
|
|
1402
|
-
this.ctx = {
|
|
1403
|
-
env,
|
|
1404
|
-
apiKey,
|
|
1405
|
-
client: initClient({
|
|
1406
|
-
env,
|
|
1407
|
-
version: _ParaCore.version,
|
|
1408
|
-
apiKey,
|
|
1409
|
-
partnerId: this.isPortal(env) ? opts.portalPartnerId : void 0,
|
|
1410
|
-
useFetchAdapter: !!opts.disableWorkers,
|
|
1411
|
-
retrieveSessionCookie: this.retrieveSessionCookie,
|
|
1412
|
-
persistSessionCookie: this.persistSessionCookie
|
|
1413
|
-
}),
|
|
1414
|
-
disableWorkers: opts.disableWorkers,
|
|
1415
|
-
offloadMPCComputationURL: opts.offloadMPCComputationURL,
|
|
1416
|
-
useLocalFiles: opts.useLocalFiles,
|
|
1417
|
-
useDKLS: opts.useDKLSForCreation || !opts.offloadMPCComputationURL,
|
|
1418
|
-
disableWebSockets: !!opts.disableWebSockets,
|
|
1419
|
-
wasmOverride: opts.wasmOverride,
|
|
1420
|
-
isE2E
|
|
1421
|
-
};
|
|
1422
|
-
if (opts.offloadMPCComputationURL) {
|
|
1423
|
-
this.ctx.mpcComputationClient = initClient2(opts.offloadMPCComputationURL, opts.disableWorkers);
|
|
1424
|
-
}
|
|
1425
|
-
if (!this.platformUtils.isSyncStorage || opts.useStorageOverrides) {
|
|
1426
|
-
return;
|
|
1427
|
-
}
|
|
1428
|
-
this.initializeFromStorage();
|
|
1429
|
-
setupListeners.bind(this)();
|
|
1430
|
-
autoBind(this);
|
|
1431
|
-
}
|
|
1432
|
-
get authInfo() {
|
|
1433
|
-
return __privateGet(this, _authInfo);
|
|
1434
|
-
}
|
|
1435
|
-
get email() {
|
|
1436
|
-
var _a;
|
|
1437
|
-
return isEmail((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) ? __privateGet(this, _authInfo).auth.email : void 0;
|
|
1438
|
-
}
|
|
1439
|
-
get phone() {
|
|
1440
|
-
var _a;
|
|
1441
|
-
return isPhone((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) ? __privateGet(this, _authInfo).auth.phone : void 0;
|
|
1442
|
-
}
|
|
1443
|
-
get farcasterUsername() {
|
|
1444
|
-
var _a;
|
|
1445
|
-
return isFarcaster((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) ? __privateGet(this, _authInfo).auth.farcasterUsername : void 0;
|
|
1446
|
-
}
|
|
1447
|
-
get telegramUserId() {
|
|
1448
|
-
var _a;
|
|
1449
|
-
return isTelegram((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) ? __privateGet(this, _authInfo).auth.telegramUserId : void 0;
|
|
1450
|
-
}
|
|
1451
|
-
get externalWalletWithParaAuth() {
|
|
1452
|
-
const externalWallets = Object.values(this.externalWallets);
|
|
1453
|
-
return externalWallets.find((w) => w.isExternalWithParaAuth);
|
|
1454
|
-
}
|
|
1455
|
-
get externalWalletConnectionType() {
|
|
1456
|
-
if (this.isExternalWalletAuth) {
|
|
1457
|
-
return "AUTHENTICATED";
|
|
1458
|
-
} else if (!!Object.keys(this.externalWallets).length) {
|
|
1459
|
-
return "CONNECTION_ONLY";
|
|
1460
|
-
}
|
|
1461
|
-
return "NONE";
|
|
1462
|
-
}
|
|
1463
|
-
get isEmail() {
|
|
1464
|
-
var _a;
|
|
1465
|
-
return isEmail((_a = this.authInfo) == null ? void 0 : _a.auth);
|
|
1466
|
-
}
|
|
1467
|
-
get isPhone() {
|
|
1468
|
-
var _a;
|
|
1469
|
-
return isPhone((_a = this.authInfo) == null ? void 0 : _a.auth);
|
|
1470
|
-
}
|
|
1471
|
-
get isFarcaster() {
|
|
1472
|
-
var _a;
|
|
1473
|
-
return isFarcaster((_a = this.authInfo) == null ? void 0 : _a.auth);
|
|
1474
|
-
}
|
|
1475
|
-
get isTelegram() {
|
|
1476
|
-
var _a;
|
|
1477
|
-
return isTelegram((_a = this.authInfo) == null ? void 0 : _a.auth);
|
|
1478
|
-
}
|
|
1479
|
-
get isExternalWalletAuth() {
|
|
1480
|
-
var _a;
|
|
1481
|
-
return isExternalWallet((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth);
|
|
1482
|
-
}
|
|
1483
|
-
get partnerId() {
|
|
1484
|
-
var _a;
|
|
1485
|
-
return (_a = __privateGet(this, _partner)) == null ? void 0 : _a.id;
|
|
1486
|
-
}
|
|
1487
|
-
get currentWalletIdsArray() {
|
|
1488
|
-
var _a, _b;
|
|
1489
|
-
return ((_b = (_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : Object.keys(this.currentWalletIds).map((type) => ({ type }))).reduce(
|
|
1490
|
-
(acc, { type }) => {
|
|
1491
|
-
var _a2;
|
|
1492
|
-
return [
|
|
1493
|
-
...acc,
|
|
1494
|
-
...((_a2 = this.currentWalletIds[type]) != null ? _a2 : []).map((id) => {
|
|
1495
|
-
return [id, type];
|
|
1496
|
-
})
|
|
1497
|
-
];
|
|
1498
|
-
},
|
|
1499
|
-
[]
|
|
1500
|
-
);
|
|
1501
|
-
}
|
|
1502
|
-
get currentWalletIdsUnique() {
|
|
1503
|
-
return [...new Set(Object.values(this.currentWalletIds).flat())];
|
|
1504
|
-
}
|
|
1505
|
-
/**
|
|
1506
|
-
* A map of pre-generated wallet identifiers that can be claimed in the current instance.
|
|
1507
|
-
*/
|
|
1508
|
-
get pregenIds() {
|
|
1509
|
-
return __spreadValues({}, Object.values(this.wallets).filter((wallet) => !this.userId || this.isPregenWalletClaimable(wallet)).reduce((acc, wallet) => {
|
|
1510
|
-
var _a, _b;
|
|
1511
|
-
if (((_a = acc[wallet.pregenIdentifierType]) != null ? _a : []).includes(wallet.pregenIdentifier)) {
|
|
1512
|
-
return acc;
|
|
1513
|
-
}
|
|
1514
|
-
return __spreadProps(__spreadValues({}, acc), {
|
|
1515
|
-
[wallet.pregenIdentifierType]: [
|
|
1516
|
-
.../* @__PURE__ */ new Set([...(_b = acc[wallet.pregenIdentifierType]) != null ? _b : [], wallet.pregenIdentifier])
|
|
1517
|
-
]
|
|
1518
|
-
});
|
|
1519
|
-
}, {}));
|
|
1520
|
-
}
|
|
1521
|
-
/**
|
|
1522
|
-
* Whether the instance has multiple wallets connected.
|
|
1523
|
-
*/
|
|
1524
|
-
get isMultiWallet() {
|
|
1525
|
-
return this.currentWalletIdsArray.length > 1;
|
|
1526
|
-
}
|
|
1527
|
-
get supportedWalletTypes() {
|
|
1528
|
-
var _a, _b;
|
|
1529
|
-
return (_b = (_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : [];
|
|
1530
|
-
}
|
|
1531
|
-
get cosmosPrefix() {
|
|
1532
|
-
var _a;
|
|
1533
|
-
return (_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix;
|
|
1534
|
-
}
|
|
1535
|
-
get isWalletTypeEnabled() {
|
|
1536
|
-
var _a;
|
|
1537
|
-
return (((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) || []).reduce((acc, { type }) => {
|
|
1538
|
-
return __spreadProps(__spreadValues({}, acc), { [type]: true });
|
|
1539
|
-
}, {});
|
|
1540
|
-
}
|
|
1541
|
-
convertBigInt(bigInt) {
|
|
1542
|
-
const convertedBigInt = new jsbn.BigInteger(null);
|
|
1543
|
-
convertedBigInt.data = bigInt.data;
|
|
1544
|
-
convertedBigInt.s = bigInt.s;
|
|
1545
|
-
convertedBigInt.t = bigInt.t;
|
|
1546
|
-
return convertedBigInt;
|
|
1547
|
-
}
|
|
1548
|
-
convertEncryptionKeyPair(jsonKeyPair) {
|
|
1549
|
-
return {
|
|
1550
|
-
privateKey: pki.setRsaPrivateKey(
|
|
1551
|
-
this.convertBigInt(jsonKeyPair.privateKey.n),
|
|
1552
|
-
this.convertBigInt(jsonKeyPair.privateKey.e),
|
|
1553
|
-
this.convertBigInt(jsonKeyPair.privateKey.d),
|
|
1554
|
-
this.convertBigInt(jsonKeyPair.privateKey.p),
|
|
1555
|
-
this.convertBigInt(jsonKeyPair.privateKey.q),
|
|
1556
|
-
this.convertBigInt(jsonKeyPair.privateKey.dP),
|
|
1557
|
-
this.convertBigInt(jsonKeyPair.privateKey.dQ),
|
|
1558
|
-
this.convertBigInt(jsonKeyPair.privateKey.qInv)
|
|
1559
|
-
),
|
|
1560
|
-
publicKey: pki.setRsaPublicKey(
|
|
1561
|
-
this.convertBigInt(jsonKeyPair.publicKey.n),
|
|
1562
|
-
this.convertBigInt(jsonKeyPair.publicKey.e)
|
|
1563
|
-
)
|
|
1564
|
-
};
|
|
1565
|
-
}
|
|
1566
|
-
isPortal(envOverride) {
|
|
1567
|
-
var _a;
|
|
1568
|
-
if (typeof window === "undefined") return false;
|
|
1569
|
-
return !!((_a = window.location) == null ? void 0 : _a.host) && getPortalBaseURL(envOverride ? { env: envOverride } : this.ctx).includes(window.location.host);
|
|
1570
|
-
}
|
|
1571
|
-
isParaConnect() {
|
|
1572
|
-
var _a;
|
|
1573
|
-
if (typeof window === "undefined") return false;
|
|
1574
|
-
return !!((_a = window.location) == null ? void 0 : _a.host) && getParaConnectBaseUrl(this.ctx).includes(window.location.host);
|
|
1575
|
-
}
|
|
1576
|
-
requireApiKey() {
|
|
1577
|
-
if (!this.ctx.apiKey) {
|
|
1578
|
-
throw new Error(
|
|
1579
|
-
`in order to create a wallet or user with Para, you
|
|
1580
|
-
must provide an API key to the Para instance`
|
|
1581
|
-
);
|
|
1582
|
-
}
|
|
1583
|
-
}
|
|
1584
|
-
isWalletSupported(wallet) {
|
|
1585
|
-
var _a, _b;
|
|
1586
|
-
return !((_a = __privateGet(this, _partner)) == null ? void 0 : _a.supportedWalletTypes) || isWalletSupported((_b = __privateGet(this, _partner).supportedWalletTypes.map(({ type }) => type)) != null ? _b : [], wallet);
|
|
1587
|
-
}
|
|
1588
|
-
isWalletOwned(wallet) {
|
|
1589
|
-
return this.isWalletSupported(wallet) && !(wallet == null ? void 0 : wallet.pregenIdentifier) && !(wallet == null ? void 0 : wallet.pregenIdentifierType) && !!this.userId && (wallet == null ? void 0 : wallet.userId) === this.userId;
|
|
1590
|
-
}
|
|
1591
|
-
isPregenWalletUnclaimed(wallet) {
|
|
1592
|
-
return this.isWalletSupported(wallet) && (!(wallet == null ? void 0 : wallet.userId) || (wallet == null ? void 0 : wallet.isPregen) && !!(wallet == null ? void 0 : wallet.pregenIdentifier) && !!(wallet == null ? void 0 : wallet.pregenIdentifierType));
|
|
1593
|
-
}
|
|
1594
|
-
isPregenWalletClaimable(wallet) {
|
|
1595
|
-
return this.isWalletSupported(wallet) && this.isPregenWalletUnclaimed(wallet) && (!["EMAIL", "PHONE", "TELEGRAM"].includes(wallet == null ? void 0 : wallet.pregenIdentifierType) || isPregenIdentifierMatch(
|
|
1596
|
-
(wallet == null ? void 0 : wallet.pregenIdentifierType) === "EMAIL" ? this.email : (wallet == null ? void 0 : wallet.pregenIdentifierType) === "TELEGRAM" ? this.telegramUserId : this.getPhoneNumber(),
|
|
1597
|
-
wallet == null ? void 0 : wallet.pregenIdentifier,
|
|
1598
|
-
wallet == null ? void 0 : wallet.pregenIdentifierType
|
|
1599
|
-
));
|
|
1600
|
-
}
|
|
1601
|
-
isWalletUsable(walletId, { type: types, scheme: schemes, forbidPregen = false } = {}, throwError = false) {
|
|
1602
|
-
var _a, _b;
|
|
1603
|
-
let error;
|
|
1604
|
-
if ((_a = this.externalWallets) == null ? void 0 : _a[walletId]) {
|
|
1605
|
-
return true;
|
|
1606
|
-
}
|
|
1607
|
-
if (!this.wallets[walletId]) {
|
|
1608
|
-
error = `wallet with id ${walletId} does not exist`;
|
|
1609
|
-
} else {
|
|
1610
|
-
const wallet = this.wallets[walletId];
|
|
1611
|
-
const [isUnclaimed, isOwned] = [this.isPregenWalletUnclaimed(wallet), this.isWalletOwned(wallet)];
|
|
1612
|
-
if (forbidPregen && isUnclaimed) {
|
|
1613
|
-
error = `pre-generated wallet with id ${wallet == null ? void 0 : wallet.id} cannot be selected`;
|
|
1614
|
-
} else if (!isOwned && !isUnclaimed) {
|
|
1615
|
-
error = `wallet with id ${wallet == null ? void 0 : wallet.id} is not owned by the current user`;
|
|
1616
|
-
} else if (!this.isWalletSupported(wallet)) {
|
|
1617
|
-
error = `wallet with id ${wallet.id} and type ${wallet.type} is not supported, supported types are: ${(((_b = __privateGet(this, _partner)) == null ? void 0 : _b.supportedWalletTypes) || []).map(({ type }) => type).join(", ")}`;
|
|
1618
|
-
} else if (types && (!getEquivalentTypes(types).includes(wallet == null ? void 0 : wallet.type) || isOwned && !types.some((type) => {
|
|
1619
|
-
var _a2, _b2;
|
|
1620
|
-
return (_b2 = (_a2 = this.currentWalletIds) == null ? void 0 : _a2[type]) == null ? void 0 : _b2.includes(walletId);
|
|
1621
|
-
}))) {
|
|
1622
|
-
error = `wallet with id ${wallet == null ? void 0 : wallet.id} and type ${wallet == null ? void 0 : wallet.type} cannot be selected`;
|
|
1623
|
-
} else if (schemes && !schemes.includes(wallet == null ? void 0 : wallet.scheme)) {
|
|
1624
|
-
error = `wallet with id ${wallet == null ? void 0 : wallet.id} and scheme ${wallet == null ? void 0 : wallet.scheme} cannot be selected`;
|
|
1625
|
-
}
|
|
1626
|
-
}
|
|
1627
|
-
if (error) {
|
|
1628
|
-
if (throwError) {
|
|
1629
|
-
throw new Error(error);
|
|
1630
|
-
}
|
|
1631
|
-
return false;
|
|
1632
|
-
}
|
|
1633
|
-
return true;
|
|
1634
|
-
}
|
|
1635
|
-
/**
|
|
1636
|
-
* Returns the formatted address for the desired wallet ID, depending on your app settings.
|
|
1637
|
-
* @param {string} walletId the ID of the wallet address to display.
|
|
1638
|
-
* @param {object} options additional options for formatting the address.
|
|
1639
|
-
* @param {boolean} options.truncate whether to truncate the address.
|
|
1640
|
-
* @param {WalletType} options.addressType the type of address to display.
|
|
1641
|
-
* @returns the formatted address
|
|
1642
|
-
*/
|
|
1643
|
-
getDisplayAddress(walletId, options = {}) {
|
|
1644
|
-
var _a, _b, _c, _d;
|
|
1645
|
-
if (this.externalWallets[walletId]) {
|
|
1646
|
-
const wallet2 = this.externalWallets[walletId];
|
|
1647
|
-
return options.truncate ? truncateAddress(wallet2.address, wallet2.type, { prefix: (_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix }) : wallet2.address;
|
|
1648
|
-
}
|
|
1649
|
-
const wallet = this.findWallet(walletId, options.addressType);
|
|
1650
|
-
if (!wallet) {
|
|
1651
|
-
return void 0;
|
|
1652
|
-
}
|
|
1653
|
-
let str;
|
|
1654
|
-
switch (wallet.type) {
|
|
1655
|
-
case WalletType2.COSMOS:
|
|
1656
|
-
str = getCosmosAddress(wallet.publicKey, (_c = (_b = __privateGet(this, _partner)) == null ? void 0 : _b.cosmosPrefix) != null ? _c : "cosmos");
|
|
1657
|
-
break;
|
|
1658
|
-
default:
|
|
1659
|
-
str = wallet.address;
|
|
1660
|
-
break;
|
|
1661
|
-
}
|
|
1662
|
-
return options.truncate ? truncateAddress(str, wallet.type, { prefix: (_d = __privateGet(this, _partner)) == null ? void 0 : _d.cosmosPrefix }) : str;
|
|
1663
|
-
}
|
|
1664
|
-
/**
|
|
1665
|
-
* Returns a unique hash for a wallet suitable for use as an identicon seed.
|
|
1666
|
-
* @param {string} walletId the ID of the wallet.
|
|
1667
|
-
* @param {boolean} options.addressType used to format the hash for another wallet type.
|
|
1668
|
-
* @returns the identicon hash string
|
|
1669
|
-
*/
|
|
1670
|
-
getIdenticonHash(walletId, overrideType) {
|
|
1671
|
-
if (this.externalWallets[walletId]) {
|
|
1672
|
-
const wallet2 = this.externalWallets[walletId];
|
|
1673
|
-
return `${wallet2.id}-${wallet2.address}-${wallet2.type}`;
|
|
1674
|
-
}
|
|
1675
|
-
const wallet = this.findWallet(walletId, overrideType);
|
|
1676
|
-
return wallet ? `${wallet.id}-${wallet.address}-${wallet.type}` : void 0;
|
|
1677
|
-
}
|
|
1678
|
-
getWallets() {
|
|
1679
|
-
return this.wallets;
|
|
1680
|
-
}
|
|
1681
|
-
getAddress(walletId) {
|
|
1682
|
-
var _a, _b, _c;
|
|
1683
|
-
return walletId ? (_a = this.wallets[walletId]) == null ? void 0 : _a.address : (_c = (_b = Object.values(this.wallets)) == null ? void 0 : _b[0]) == null ? void 0 : _c.address;
|
|
1684
|
-
}
|
|
1685
|
-
constructPortalUrl(_0) {
|
|
1686
|
-
return __async(this, arguments, function* (type, opts = {}) {
|
|
1687
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
1688
|
-
const [isCreate, isLogin, isOnRamp] = [
|
|
1689
|
-
["createAuth", "createPassword"].includes(type),
|
|
1690
|
-
["loginAuth", "loginPassword"].includes(type),
|
|
1691
|
-
type === "onRamp"
|
|
1692
|
-
];
|
|
1693
|
-
let auth;
|
|
1694
|
-
if (isCreate || isLogin) {
|
|
1695
|
-
auth = this.assertIsAuthSet().auth;
|
|
1696
|
-
}
|
|
1697
|
-
let sessionId = opts.sessionId;
|
|
1698
|
-
if ((isLogin || isOnRamp) && !sessionId) {
|
|
1699
|
-
const session = yield this.touchSession(true);
|
|
1700
|
-
sessionId = session.sessionId;
|
|
1701
|
-
}
|
|
1702
|
-
if (!this.loginEncryptionKeyPair) {
|
|
1703
|
-
yield this.setLoginEncryptionKeyPair();
|
|
1704
|
-
}
|
|
1705
|
-
const base = type === "onRamp" ? getPortalBaseURL(this.ctx) : yield this.getPortalURL();
|
|
1706
|
-
let path;
|
|
1707
|
-
switch (type) {
|
|
1708
|
-
case "createPassword": {
|
|
1709
|
-
path = `/web/users/${this.userId}/passwords/${opts.pathId}`;
|
|
1710
|
-
break;
|
|
1711
|
-
}
|
|
1712
|
-
case "createAuth": {
|
|
1713
|
-
path = `/web/users/${this.userId}/biometrics/${opts.pathId}`;
|
|
1714
|
-
break;
|
|
1715
|
-
}
|
|
1716
|
-
case "loginPassword": {
|
|
1717
|
-
path = "/web/passwords/login";
|
|
1718
|
-
break;
|
|
1719
|
-
}
|
|
1720
|
-
case "loginAuth": {
|
|
1721
|
-
path = "/web/biometrics/login";
|
|
1722
|
-
break;
|
|
1723
|
-
}
|
|
1724
|
-
case "txReview": {
|
|
1725
|
-
path = `/web/users/${this.userId}/transaction-review/${opts.pathId}`;
|
|
1726
|
-
break;
|
|
1727
|
-
}
|
|
1728
|
-
case "onRamp": {
|
|
1729
|
-
path = `/web/users/${this.userId}/on-ramp-transaction/${opts.pathId}`;
|
|
1730
|
-
break;
|
|
1731
|
-
}
|
|
1732
|
-
default: {
|
|
1733
|
-
throw new Error(`invalid URL type ${type}`);
|
|
1734
|
-
}
|
|
1735
|
-
}
|
|
1736
|
-
const partner = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1737
|
-
const thisDevice = (_a = opts.thisDevice) != null ? _a : {
|
|
1738
|
-
encryptionKey: getPublicKeyHex(this.loginEncryptionKeyPair),
|
|
1739
|
-
sessionId
|
|
1740
|
-
};
|
|
1741
|
-
const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
1742
|
-
apiKey: this.ctx.apiKey,
|
|
1743
|
-
partnerId: partner.id,
|
|
1744
|
-
portalFont: ((_b = opts.portalTheme) == null ? void 0 : _b.font) || (partner == null ? void 0 : partner.font) || ((_c = this.portalTheme) == null ? void 0 : _c.font),
|
|
1745
|
-
portalBorderRadius: ((_d = opts.portalTheme) == null ? void 0 : _d.borderRadius) || ((_e = this.portalTheme) == null ? void 0 : _e.borderRadius),
|
|
1746
|
-
portalThemeMode: ((_f = opts.portalTheme) == null ? void 0 : _f.mode) || (partner == null ? void 0 : partner.themeMode) || ((_g = this.portalTheme) == null ? void 0 : _g.mode),
|
|
1747
|
-
portalAccentColor: ((_h = opts.portalTheme) == null ? void 0 : _h.accentColor) || (partner == null ? void 0 : partner.accentColor) || ((_i = this.portalTheme) == null ? void 0 : _i.accentColor),
|
|
1748
|
-
portalForegroundColor: ((_j = opts.portalTheme) == null ? void 0 : _j.foregroundColor) || (partner == null ? void 0 : partner.foregroundColor) || ((_k = this.portalTheme) == null ? void 0 : _k.foregroundColor),
|
|
1749
|
-
portalBackgroundColor: ((_l = opts.portalTheme) == null ? void 0 : _l.backgroundColor) || (partner == null ? void 0 : partner.backgroundColor) || this.portalBackgroundColor || ((_m = this.portalTheme) == null ? void 0 : _m.backgroundColor),
|
|
1750
|
-
portalPrimaryButtonColor: this.portalPrimaryButtonColor,
|
|
1751
|
-
portalTextColor: this.portalTextColor,
|
|
1752
|
-
portalPrimaryButtonTextColor: this.portalPrimaryButtonTextColor,
|
|
1753
|
-
isForNewDevice: opts.isForNewDevice ? opts.isForNewDevice.toString() : void 0
|
|
1754
|
-
}, auth && (isCreate || isLogin) ? auth : {}), isOnRamp ? { sessionId } : {}), isLogin ? __spreadProps(__spreadValues({
|
|
1755
|
-
sessionId: thisDevice.sessionId,
|
|
1756
|
-
encryptionKey: thisDevice.encryptionKey
|
|
1757
|
-
}, opts.newDevice ? {
|
|
1758
|
-
newDeviceSessionLookupId: opts.newDevice.sessionId,
|
|
1759
|
-
newDeviceEncryptionKey: opts.newDevice.encryptionKey
|
|
1760
|
-
} : {}), {
|
|
1761
|
-
pregenIds: JSON.stringify(this.pregenIds)
|
|
1762
|
-
}) : {}), opts.params || {});
|
|
1763
|
-
const url = constructUrl({ base, path, params });
|
|
1764
|
-
if (opts.shorten) {
|
|
1765
|
-
return shortenUrl(this.ctx, url);
|
|
1766
|
-
}
|
|
1767
|
-
return url;
|
|
1768
|
-
});
|
|
1769
|
-
}
|
|
1770
|
-
touchSession(regenerate = false) {
|
|
1771
|
-
return __async(this, null, function* () {
|
|
1772
|
-
var _a, _b, _c;
|
|
1773
|
-
const session = yield this.ctx.client.touchSession(regenerate);
|
|
1774
|
-
if (!__privateGet(this, _partner) || ((_a = __privateGet(this, _partner)) == null ? void 0 : _a.id) !== session.partnerId || !supportedWalletTypesEq(((_b = __privateGet(this, _partner)) == null ? void 0 : _b.supportedWalletTypes) || [], session.supportedWalletTypes) || (((_c = __privateGet(this, _partner)) == null ? void 0 : _c.cosmosPrefix) || "cosmos") !== session.cosmosPrefix) {
|
|
1775
|
-
yield __privateMethod(this, _ParaCore_instances, getPartner_fn).call(this, session.partnerId);
|
|
1776
|
-
}
|
|
1777
|
-
return session;
|
|
1778
|
-
});
|
|
1779
|
-
}
|
|
1780
|
-
getVerificationEmailProps() {
|
|
1781
|
-
return {
|
|
1782
|
-
brandColor: this.emailPrimaryColor,
|
|
1783
|
-
theme: this.emailTheme,
|
|
1784
|
-
supportUrl: this.supportUrl,
|
|
1785
|
-
homepageUrl: this.homepageUrl,
|
|
1786
|
-
xUrl: this.xUrl,
|
|
1787
|
-
githubUrl: this.githubUrl,
|
|
1788
|
-
linkedinUrl: this.linkedinUrl
|
|
1789
|
-
};
|
|
1790
|
-
}
|
|
1791
|
-
getBackupKitEmailProps() {
|
|
1792
|
-
return {
|
|
1793
|
-
brandColor: this.emailPrimaryColor,
|
|
1794
|
-
theme: this.emailTheme,
|
|
1795
|
-
homepageUrl: this.homepageUrl,
|
|
1796
|
-
xUrl: this.xUrl,
|
|
1797
|
-
linkedinUrl: this.linkedinUrl,
|
|
1798
|
-
githubUrl: this.githubUrl,
|
|
1799
|
-
supportUrl: this.supportUrl
|
|
1800
|
-
};
|
|
1801
|
-
}
|
|
1802
|
-
/**
|
|
1803
|
-
* Initialize storage relating to a `ParaCore` instance.
|
|
1804
|
-
*
|
|
1805
|
-
* Init only needs to be called for storage that is async.
|
|
1806
|
-
*/
|
|
1807
|
-
init() {
|
|
1808
|
-
return __async(this, null, function* () {
|
|
1809
|
-
var _a, _b;
|
|
1810
|
-
this.userId = (yield this.localStorageGetItem(LOCAL_STORAGE_USER_ID)) || void 0;
|
|
1811
|
-
const storageAuthInfo = (yield this.localStorageGetItem(LOCAL_STORAGE_AUTH_INFO)) || void 0;
|
|
1812
|
-
const stringExternalWallets = yield this.localStorageGetItem(LOCAL_STORAGE_EXTERNAL_WALLETS);
|
|
1813
|
-
const _externalWallets = JSON.parse(stringExternalWallets || "{}");
|
|
1814
|
-
yield this.setExternalWallets(_externalWallets);
|
|
1815
|
-
let authInfo = jsonParse(storageAuthInfo);
|
|
1816
|
-
if (!authInfo) {
|
|
1817
|
-
const authParams = {
|
|
1818
|
-
email: (yield this.localStorageGetItem(LOCAL_STORAGE_EMAIL)) || void 0,
|
|
1819
|
-
phone: (yield this.localStorageGetItem(LOCAL_STORAGE_PHONE)) || void 0,
|
|
1820
|
-
countryCode: (yield this.localStorageGetItem(LOCAL_STORAGE_COUNTRY_CODE)) || void 0,
|
|
1821
|
-
farcasterUsername: (yield this.localStorageGetItem(LOCAL_STORAGE_FARCASTER_USERNAME)) || void 0,
|
|
1822
|
-
telegramUserId: (yield this.localStorageGetItem(LOCAL_STORAGE_TELEGRAM_USER_ID)) || void 0,
|
|
1823
|
-
// Using id here since we store the bech32 address for cosmos in the address field of the wallet
|
|
1824
|
-
externalWalletAddress: ((_a = this.externalWalletWithParaAuth) == null ? void 0 : _a.id) || void 0
|
|
1825
|
-
};
|
|
1826
|
-
authInfo = __privateMethod(this, _ParaCore_instances, toAuthInfo_fn).call(this, authParams);
|
|
1827
|
-
}
|
|
1828
|
-
__privateSet(this, _authInfo, authInfo);
|
|
1829
|
-
const stringWallets = this.platformUtils.secureStorage ? yield this.platformUtils.secureStorage.get(LOCAL_STORAGE_WALLETS) : yield this.localStorageGetItem(LOCAL_STORAGE_WALLETS);
|
|
1830
|
-
const _wallets = JSON.parse(stringWallets || "{}");
|
|
1831
|
-
const stringEd25519Wallets = this.platformUtils.secureStorage ? yield this.platformUtils.secureStorage.get(LOCAL_STORAGE_ED25519_WALLETS) : yield this.localStorageGetItem(LOCAL_STORAGE_ED25519_WALLETS);
|
|
1832
|
-
const _ed25519Wallets = JSON.parse(stringEd25519Wallets || "{}");
|
|
1833
|
-
const wallets = __spreadValues(__spreadValues({}, Object.keys(_wallets).reduce((res, key) => {
|
|
1834
|
-
return __spreadProps(__spreadValues({}, res), {
|
|
1835
|
-
[key]: migrateWallet(_wallets[key])
|
|
1836
|
-
});
|
|
1837
|
-
}, {})), Object.keys(_ed25519Wallets).reduce((res, key) => {
|
|
1838
|
-
return __spreadValues(__spreadValues({}, res), !res[key] ? { [key]: migrateWallet(_ed25519Wallets[key]) } : {});
|
|
1839
|
-
}, {}));
|
|
1840
|
-
yield this.setWallets(wallets);
|
|
1841
|
-
const _currentWalletIds = (_b = yield this.localStorageGetItem(LOCAL_STORAGE_CURRENT_WALLET_IDS)) != null ? _b : void 0;
|
|
1842
|
-
const currentWalletIds = [void 0, null, "undefined", "null"].includes(_currentWalletIds) ? {} : (() => {
|
|
1843
|
-
const fromJson = JSON.parse(_currentWalletIds);
|
|
1844
|
-
return Array.isArray(fromJson) ? Object.keys(WalletType2).reduce((acc, type) => {
|
|
1845
|
-
const wallet = Object.values(this.wallets).find(
|
|
1846
|
-
(w) => fromJson.includes(w.id) && WalletSchemeTypeMap[w.scheme][type]
|
|
1847
|
-
);
|
|
1848
|
-
return __spreadValues(__spreadValues({}, acc), wallet && !acc[type] ? { [type]: [wallet.id] } : {});
|
|
1849
|
-
}, {}) : fromJson;
|
|
1850
|
-
})();
|
|
1851
|
-
yield this.setCurrentWalletIds(currentWalletIds);
|
|
1852
|
-
this.sessionCookie = (yield this.localStorageGetItem(LOCAL_STORAGE_SESSION_COOKIE)) || (yield this.sessionStorageGetItem(LOCAL_STORAGE_SESSION_COOKIE)) || void 0;
|
|
1853
|
-
if (Object.values(this.wallets).filter((w) => this.isWalletOwned(w)).length > 0 && this.currentWalletIdsArray.length === 0) {
|
|
1854
|
-
this.findWalletId(void 0, { forbidPregen: true });
|
|
1855
|
-
}
|
|
1856
|
-
const loginEncryptionKey = yield this.sessionStorageGetItem(SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR);
|
|
1857
|
-
if (loginEncryptionKey && loginEncryptionKey !== "undefined") {
|
|
1858
|
-
this.loginEncryptionKeyPair = this.convertEncryptionKeyPair(JSON.parse(loginEncryptionKey));
|
|
1859
|
-
}
|
|
1860
|
-
setupListeners.bind(this)();
|
|
1861
|
-
yield this.touchSession();
|
|
1862
|
-
});
|
|
1863
|
-
}
|
|
1864
|
-
setAuth(_0) {
|
|
1865
|
-
return __async(this, arguments, function* (auth, { extras = {}, userId } = {}) {
|
|
1866
|
-
const authInfo = __spreadValues(__spreadValues({}, extractAuthInfo(auth, { isRequired: true })), extras || {});
|
|
1867
|
-
yield __privateMethod(this, _ParaCore_instances, setAuthInfo_fn).call(this, authInfo);
|
|
1868
|
-
if (!!userId) {
|
|
1869
|
-
yield this.setUserId(userId);
|
|
1870
|
-
}
|
|
1871
|
-
return __privateGet(this, _authInfo);
|
|
1872
|
-
});
|
|
1873
|
-
}
|
|
1874
|
-
assertUserId() {
|
|
1875
|
-
if (!this.userId) {
|
|
1876
|
-
throw new Error("no userId is set");
|
|
1877
|
-
}
|
|
1878
|
-
return this.userId;
|
|
1879
|
-
}
|
|
1880
|
-
assertIsAuthSet(allowed) {
|
|
1881
|
-
if (!__privateGet(this, _authInfo)) {
|
|
1882
|
-
throw new Error("auth is not set");
|
|
1883
|
-
}
|
|
1884
|
-
if (allowed && !allowed.includes(__privateGet(this, _authInfo).authType)) {
|
|
1885
|
-
throw new Error(`invalid auth type, expected ${allowed.join(", ")}`);
|
|
1886
|
-
}
|
|
1887
|
-
return __privateGet(this, _authInfo);
|
|
1888
|
-
}
|
|
1889
|
-
/**
|
|
1890
|
-
* Sets the email associated with the `ParaCore` instance.
|
|
1891
|
-
* @param email - Email to set.
|
|
1892
|
-
*/
|
|
1893
|
-
setEmail(email) {
|
|
1894
|
-
return __async(this, null, function* () {
|
|
1895
|
-
yield this.setAuth({ email });
|
|
1896
|
-
});
|
|
1897
|
-
}
|
|
1898
|
-
/**
|
|
1899
|
-
* Sets the Telegram user ID associated with the `ParaCore` instance.
|
|
1900
|
-
* @param telegramUserId - Telegram user ID to set.
|
|
1901
|
-
*/
|
|
1902
|
-
setTelegramUserId(telegramUserId) {
|
|
1903
|
-
return __async(this, null, function* () {
|
|
1904
|
-
yield this.setAuth({ telegramUserId });
|
|
1905
|
-
});
|
|
1906
|
-
}
|
|
1907
|
-
/**
|
|
1908
|
-
* Sets the phone number associated with the `ParaCore` instance.
|
|
1909
|
-
* @param phone - Phone number to set.
|
|
1910
|
-
* @param countryCode - Country Code to set.
|
|
1911
|
-
*/
|
|
1912
|
-
setPhone(phone, countryCode) {
|
|
1913
|
-
return __async(this, null, function* () {
|
|
1914
|
-
yield this.setAuth({ phone: formatPhoneNumber(phone, countryCode) });
|
|
1915
|
-
});
|
|
1916
|
-
}
|
|
1917
|
-
/**
|
|
1918
|
-
* Sets the farcaster username associated with the `ParaCore` instance.
|
|
1919
|
-
* @param farcasterUsername - Farcaster Username to set.
|
|
1920
|
-
*/
|
|
1921
|
-
setFarcasterUsername(farcasterUsername) {
|
|
1922
|
-
return __async(this, null, function* () {
|
|
1923
|
-
yield this.setAuth({ farcasterUsername });
|
|
1924
|
-
});
|
|
1925
|
-
}
|
|
1926
|
-
/**
|
|
1927
|
-
* Sets the external wallet address and type associated with the `ParaCore` instance.
|
|
1928
|
-
* @param externalAddress - External wallet address to set.
|
|
1929
|
-
* @param externalType - Type of external wallet to set.
|
|
1930
|
-
*/
|
|
1931
|
-
setExternalWallet(_0) {
|
|
1932
|
-
return __async(this, arguments, function* ({ address, type, provider, addressBech32, withFullParaAuth }) {
|
|
1933
|
-
this.externalWallets = {
|
|
1934
|
-
[address]: {
|
|
1935
|
-
id: address,
|
|
1936
|
-
address: addressBech32 != null ? addressBech32 : address,
|
|
1937
|
-
type,
|
|
1938
|
-
name: provider,
|
|
1939
|
-
isExternal: true,
|
|
1940
|
-
isExternalWithParaAuth: withFullParaAuth,
|
|
1941
|
-
signer: ""
|
|
1942
|
-
}
|
|
1943
|
-
};
|
|
1944
|
-
this.setExternalWallets(this.externalWallets);
|
|
1945
|
-
dispatchEvent(ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, null);
|
|
1946
|
-
});
|
|
1947
|
-
}
|
|
1948
|
-
/**
|
|
1949
|
-
* Sets the user id associated with the `ParaCore` instance.
|
|
1950
|
-
* @param userId - User id to set.
|
|
1951
|
-
*/
|
|
1952
|
-
setUserId(userId) {
|
|
1953
|
-
return __async(this, null, function* () {
|
|
1954
|
-
this.userId = userId;
|
|
1955
|
-
yield this.localStorageSetItem(LOCAL_STORAGE_USER_ID, userId);
|
|
1956
|
-
});
|
|
1957
|
-
}
|
|
1958
|
-
/**
|
|
1959
|
-
* Sets the wallets associated with the `ParaCore` instance.
|
|
1960
|
-
* @param wallets - Wallets to set.
|
|
1961
|
-
*/
|
|
1962
|
-
setWallets(wallets) {
|
|
1963
|
-
return __async(this, null, function* () {
|
|
1964
|
-
this.wallets = wallets;
|
|
1965
|
-
if (this.platformUtils.secureStorage) {
|
|
1966
|
-
yield this.platformUtils.secureStorage.set(LOCAL_STORAGE_WALLETS, JSON.stringify(wallets));
|
|
1967
|
-
return;
|
|
1968
|
-
}
|
|
1969
|
-
yield this.localStorageSetItem(LOCAL_STORAGE_WALLETS, JSON.stringify(wallets));
|
|
1970
|
-
});
|
|
1971
|
-
}
|
|
1972
|
-
/**
|
|
1973
|
-
* Sets the external wallets associated with the `ParaCore` instance.
|
|
1974
|
-
* @param externalWallets - External wallets to set.
|
|
1975
|
-
*/
|
|
1976
|
-
setExternalWallets(externalWallets) {
|
|
1977
|
-
return __async(this, null, function* () {
|
|
1978
|
-
this.externalWallets = externalWallets;
|
|
1979
|
-
yield this.localStorageSetItem(LOCAL_STORAGE_EXTERNAL_WALLETS, JSON.stringify(externalWallets));
|
|
1980
|
-
});
|
|
1981
|
-
}
|
|
1982
|
-
/**
|
|
1983
|
-
* Sets the login encryption key pair associated with the `ParaCore` instance.
|
|
1984
|
-
* @param keyPair - Encryption key pair generated from loginEncryptionKey.
|
|
1985
|
-
*/
|
|
1986
|
-
setLoginEncryptionKeyPair(keyPair) {
|
|
1987
|
-
return __async(this, null, function* () {
|
|
1988
|
-
if (!keyPair) {
|
|
1989
|
-
keyPair = yield getAsymmetricKeyPair(this.ctx);
|
|
1990
|
-
}
|
|
1991
|
-
this.loginEncryptionKeyPair = keyPair;
|
|
1992
|
-
yield this.sessionStorageSetItem(SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR, JSON.stringify(keyPair));
|
|
1993
|
-
});
|
|
1994
|
-
}
|
|
1995
|
-
deleteLoginEncryptionKeyPair() {
|
|
1996
|
-
return __async(this, null, function* () {
|
|
1997
|
-
this.loginEncryptionKeyPair = void 0;
|
|
1998
|
-
yield this.sessionStorageRemoveItem(SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR);
|
|
1999
|
-
});
|
|
2000
|
-
}
|
|
2001
|
-
/**
|
|
2002
|
-
* Gets the userId associated with the `ParaCore` instance.
|
|
2003
|
-
* @returns - userId associated with the `ParaCore` instance.
|
|
2004
|
-
*/
|
|
2005
|
-
getUserId() {
|
|
2006
|
-
return this.userId;
|
|
2007
|
-
}
|
|
2008
|
-
/**
|
|
2009
|
-
* Gets the email associated with the `ParaCore` instance.
|
|
2010
|
-
* @returns - email associated with the `ParaCore` instance.
|
|
2011
|
-
*/
|
|
2012
|
-
getEmail() {
|
|
2013
|
-
return this.email;
|
|
2014
|
-
}
|
|
2015
|
-
/**
|
|
2016
|
-
* Gets the formatted phone number associated with the `ParaCore` instance.
|
|
2017
|
-
* @returns - formatted phone number associated with the `ParaCore` instance.
|
|
2018
|
-
*/
|
|
2019
|
-
getPhoneNumber() {
|
|
2020
|
-
return this.phone;
|
|
2021
|
-
}
|
|
2022
|
-
/**
|
|
2023
|
-
* Gets the farcaster username associated with the `ParaCore` instance.
|
|
2024
|
-
* @returns - farcaster username associated with the `ParaCore` instance.
|
|
2025
|
-
*/
|
|
2026
|
-
getFarcasterUsername() {
|
|
2027
|
-
return this.farcasterUsername;
|
|
2028
|
-
}
|
|
2029
|
-
setCurrentWalletIds(_0) {
|
|
2030
|
-
return __async(this, arguments, function* (currentWalletIds, {
|
|
2031
|
-
needsWallet = false,
|
|
2032
|
-
sessionLookupId,
|
|
2033
|
-
newDeviceSessionLookupId
|
|
2034
|
-
} = {}) {
|
|
2035
|
-
this.currentWalletIds = currentWalletIds;
|
|
2036
|
-
yield this.localStorageSetItem(LOCAL_STORAGE_CURRENT_WALLET_IDS, JSON.stringify(this.currentWalletIds));
|
|
2037
|
-
if (sessionLookupId) {
|
|
2038
|
-
yield this.ctx.client.setCurrentWalletIds(
|
|
2039
|
-
this.getUserId(),
|
|
2040
|
-
this.currentWalletIds,
|
|
2041
|
-
needsWallet,
|
|
2042
|
-
sessionLookupId,
|
|
2043
|
-
newDeviceSessionLookupId
|
|
2044
|
-
);
|
|
2045
|
-
}
|
|
2046
|
-
dispatchEvent(ParaEvent.WALLETS_CHANGE_EVENT, null);
|
|
2047
|
-
});
|
|
2048
|
-
}
|
|
2049
|
-
/**
|
|
2050
|
-
* Validates that a wallet ID is present on the instance, usable, and matches the desired filters.
|
|
2051
|
-
* If no ID is passed, this will instead return the first valid, usable wallet ID that matches the filters.
|
|
2052
|
-
* @param {string} [walletId] the wallet ID to validate.
|
|
2053
|
-
* @param {WalletFilters} [filter={}] a `WalletFilters` object specifying allowed types, schemes, and whether to forbid unclaimed pregen wallets.
|
|
2054
|
-
* @returns {string} the wallet ID originally passed, or the one found.
|
|
2055
|
-
*/
|
|
2056
|
-
findWalletId(walletId, filter = {}) {
|
|
2057
|
-
if (walletId) {
|
|
2058
|
-
this.assertIsValidWalletId(walletId, filter);
|
|
2059
|
-
} else {
|
|
2060
|
-
for (const id of [...this.currentWalletIdsUnique, ...Object.keys(this.wallets)]) {
|
|
2061
|
-
if (this.isWalletUsable(id, filter)) {
|
|
2062
|
-
walletId = id;
|
|
2063
|
-
break;
|
|
2064
|
-
}
|
|
2065
|
-
}
|
|
2066
|
-
if (!walletId) {
|
|
2067
|
-
throw new Error(`no valid wallet id found`);
|
|
2068
|
-
}
|
|
2069
|
-
}
|
|
2070
|
-
return walletId;
|
|
2071
|
-
}
|
|
2072
|
-
/**
|
|
2073
|
-
* Retrieves a wallet with the given address, if present.
|
|
2074
|
-
* If no ID is passed, this will instead return the first valid, usable wallet ID that matches the filters.
|
|
2075
|
-
* @param {string} [walletId] the wallet ID to validate.
|
|
2076
|
-
* @param {WalletFilters} [filter={}] a `WalletFilters` object specifying allowed types, schemes, and whether to forbid unclaimed pregen wallets.
|
|
2077
|
-
* @returns {string} the wallet ID originally passed, or the one found.
|
|
2078
|
-
*/
|
|
2079
|
-
findWalletByAddress(address, filter) {
|
|
2080
|
-
if (this.externalWallets[address]) {
|
|
2081
|
-
return this.externalWallets[address];
|
|
2082
|
-
}
|
|
2083
|
-
let wallet;
|
|
2084
|
-
Object.entries(this.currentWalletIds).forEach(([type, walletIds]) => {
|
|
2085
|
-
const pregenWalletIds = Object.keys(this.wallets).filter(
|
|
2086
|
-
(id) => this.wallets[id].type === type && this.isPregenWalletClaimable(this.wallets[id])
|
|
2087
|
-
);
|
|
2088
|
-
[...walletIds, ...pregenWalletIds].forEach((id) => {
|
|
2089
|
-
if (address.toLowerCase() === this.getDisplayAddress(id, { addressType: type }).toLowerCase()) {
|
|
2090
|
-
wallet = this.wallets[id];
|
|
2091
|
-
}
|
|
2092
|
-
});
|
|
2093
|
-
});
|
|
2094
|
-
if (!wallet) {
|
|
2095
|
-
throw new Error(`wallet with address ${address} not found`);
|
|
2096
|
-
}
|
|
2097
|
-
this.assertIsValidWalletId(wallet.id, filter);
|
|
2098
|
-
return wallet;
|
|
2099
|
-
}
|
|
2100
|
-
findWallet(idOrAddress, overrideType, filter = {}) {
|
|
2101
|
-
var _a, _c, _d;
|
|
2102
|
-
if (!this.isExternalWalletAuth) {
|
|
2103
|
-
if (!idOrAddress && Object.keys(this.externalWallets).length > 0) {
|
|
2104
|
-
return Object.values(this.externalWallets)[0];
|
|
2105
|
-
}
|
|
2106
|
-
}
|
|
2107
|
-
if ((_a = this.externalWallets) == null ? void 0 : _a[idOrAddress]) {
|
|
2108
|
-
return this.externalWallets[idOrAddress];
|
|
2109
|
-
}
|
|
2110
|
-
try {
|
|
2111
|
-
const walletId = this.findWalletId(idOrAddress, filter);
|
|
2112
|
-
if (walletId && !!this.wallets[walletId]) {
|
|
2113
|
-
const _b = this.wallets[walletId], { signer: _signer } = _b, wallet = __objRest(_b, ["signer"]);
|
|
2114
|
-
const type = (_d = overrideType != null ? overrideType : (_c = this.currentWalletIdsArray.find(([id]) => id === walletId)) == null ? void 0 : _c[1]) != null ? _d : wallet.type;
|
|
2115
|
-
return __spreadProps(__spreadValues({}, wallet), {
|
|
2116
|
-
type: WalletType2[type]
|
|
2117
|
-
});
|
|
2118
|
-
}
|
|
2119
|
-
} catch (e) {
|
|
2120
|
-
return void 0;
|
|
2121
|
-
}
|
|
2122
|
-
}
|
|
2123
|
-
get availableWallets() {
|
|
2124
|
-
var _a;
|
|
2125
|
-
return [
|
|
2126
|
-
...this.currentWalletIdsArray.map(([address, type]) => [address, type, false]).map(([id, type]) => {
|
|
2127
|
-
const wallet = this.findWallet(id, type);
|
|
2128
|
-
if (!wallet) return null;
|
|
2129
|
-
return {
|
|
2130
|
-
id: wallet.id,
|
|
2131
|
-
type,
|
|
2132
|
-
address: this.getDisplayAddress(id, { addressType: type }),
|
|
2133
|
-
name: wallet.name
|
|
2134
|
-
};
|
|
2135
|
-
}).filter((obj) => obj !== null),
|
|
2136
|
-
...Object.values((_a = this.externalWallets) != null ? _a : {})
|
|
2137
|
-
];
|
|
2138
|
-
}
|
|
2139
|
-
/**
|
|
2140
|
-
* Retrieves all usable wallets with the provided type (`'EVM' | 'COSMOS' | 'SOLANA'`)
|
|
2141
|
-
* @param {string} type the wallet type to filter by.
|
|
2142
|
-
* @returns {Wallet[]} an array of matching wallets.
|
|
2143
|
-
*/
|
|
2144
|
-
getWalletsByType(type) {
|
|
2145
|
-
return Object.values(this.wallets).filter((w) => this.isWalletUsable(w.id, { type: [type] }));
|
|
2146
|
-
}
|
|
2147
|
-
assertIsValidWalletId(walletId, condition = {}) {
|
|
2148
|
-
this.isWalletUsable(walletId, condition, true);
|
|
2149
|
-
}
|
|
2150
|
-
assertIsValidWalletType(type, walletTypes) {
|
|
2151
|
-
return __async(this, null, function* () {
|
|
2152
|
-
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2153
|
-
if (!type || !Object.values(WalletType2).includes(type) || !(walletTypes != null ? walletTypes : supportedWalletTypes.map(({ type: type2 }) => type2)).includes(type)) {
|
|
2154
|
-
throw new Error(`wallet type ${type} is not supported`);
|
|
2155
|
-
}
|
|
2156
|
-
return type;
|
|
2157
|
-
});
|
|
2158
|
-
}
|
|
2159
|
-
getMissingTypes() {
|
|
2160
|
-
return __async(this, null, function* () {
|
|
2161
|
-
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2162
|
-
return supportedWalletTypes.filter(
|
|
2163
|
-
({ type: t, optional }) => !optional && Object.values(this.wallets).every((w) => !this.isWalletOwned(w) || !WalletSchemeTypeMap[w.scheme][t])
|
|
2164
|
-
).map(({ type }) => type);
|
|
2165
|
-
});
|
|
2166
|
-
}
|
|
2167
|
-
getTypesToCreate(types) {
|
|
2168
|
-
return __async(this, null, function* () {
|
|
2169
|
-
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2170
|
-
return getSchemes(types != null ? types : yield this.getMissingTypes()).map((scheme) => {
|
|
2171
|
-
switch (scheme) {
|
|
2172
|
-
case WalletScheme2.ED25519:
|
|
2173
|
-
return WalletType2.SOLANA;
|
|
2174
|
-
default:
|
|
2175
|
-
return supportedWalletTypes.some(({ type, optional }) => type === WalletType2.COSMOS && !optional) ? WalletType2.COSMOS : WalletType2.EVM;
|
|
2176
|
-
}
|
|
2177
|
-
});
|
|
2178
|
-
});
|
|
2179
|
-
}
|
|
2180
|
-
getPartnerURL() {
|
|
2181
|
-
return __async(this, null, function* () {
|
|
2182
|
-
const { portalUrl } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2183
|
-
return portalUrl;
|
|
2184
|
-
});
|
|
2185
|
-
}
|
|
2186
|
-
/**
|
|
2187
|
-
* URL of the portal, which can be associated with a partner id
|
|
2188
|
-
* @param partnerId: string - id of the partner to get the portal URL for
|
|
2189
|
-
* @returns - portal URL
|
|
2190
|
-
*/
|
|
2191
|
-
getPortalURL() {
|
|
2192
|
-
return __async(this, null, function* () {
|
|
2193
|
-
return (yield this.getPartnerURL()) || getPortalBaseURL(this.ctx);
|
|
2194
|
-
});
|
|
2195
|
-
}
|
|
2196
|
-
/**
|
|
2197
|
-
* Gets the private key for the given wallet.
|
|
2198
|
-
* @param {string } [walletId] id of the wallet to get the private key for. Will default to the first wallet if not provided.
|
|
2199
|
-
* @returns - the private key string.
|
|
2200
|
-
*/
|
|
2201
|
-
getPrivateKey(walletId) {
|
|
2202
|
-
return __async(this, null, function* () {
|
|
2203
|
-
const wallets = Object.values(this.wallets);
|
|
2204
|
-
const wallet = walletId ? this.wallets[walletId] : wallets == null ? void 0 : wallets[0];
|
|
2205
|
-
if (!wallet) {
|
|
2206
|
-
throw new Error("wallet not found");
|
|
2207
|
-
}
|
|
2208
|
-
if (wallet.scheme !== WalletScheme2.DKLS) {
|
|
2209
|
-
throw new Error("invalid wallet scheme");
|
|
2210
|
-
}
|
|
2211
|
-
return yield this.platformUtils.getPrivateKey(
|
|
2212
|
-
this.ctx,
|
|
2213
|
-
this.userId,
|
|
2214
|
-
wallet.id,
|
|
2215
|
-
wallet.signer,
|
|
2216
|
-
this.retrieveSessionCookie()
|
|
2217
|
-
);
|
|
2218
|
-
});
|
|
2219
|
-
}
|
|
2220
|
-
/**
|
|
2221
|
-
* Fetches the wallets associated with the user.
|
|
2222
|
-
* @returns {WalletEntity[]} wallets that were fetched.
|
|
2223
|
-
*/
|
|
2224
|
-
fetchWallets() {
|
|
2225
|
-
return __async(this, null, function* () {
|
|
2226
|
-
const res = yield this.isPortal() || this.isParaConnect() ? this.ctx.client.getAllWallets(this.userId) : this.ctx.client.getWallets(this.userId, true);
|
|
2227
|
-
return res.data.wallets.filter(
|
|
2228
|
-
(wallet) => !!wallet.address && (this.isParaConnect() || !this.isParaConnect() && this.isWalletSupported(entityToWallet(wallet)))
|
|
2229
|
-
);
|
|
2230
|
-
});
|
|
2231
|
-
}
|
|
2232
|
-
populateWalletAddresses() {
|
|
2233
|
-
return __async(this, null, function* () {
|
|
2234
|
-
const res = yield this.ctx.client.getWallets(this.userId, true);
|
|
2235
|
-
const wallets = res.data.wallets;
|
|
2236
|
-
wallets.forEach((entity) => {
|
|
2237
|
-
if (this.wallets[entity.id]) {
|
|
2238
|
-
this.wallets[entity.id] = __spreadValues(__spreadValues({}, entityToWallet(entity)), this.wallets[entity.id]);
|
|
2239
|
-
}
|
|
2240
|
-
});
|
|
2241
|
-
yield this.setWallets(this.wallets);
|
|
2242
|
-
});
|
|
2243
|
-
}
|
|
2244
|
-
populatePregenWalletAddresses() {
|
|
2245
|
-
return __async(this, null, function* () {
|
|
2246
|
-
const res = yield this.getPregenWallets();
|
|
2247
|
-
res.forEach((entity) => {
|
|
2248
|
-
if (this.wallets[entity.id]) {
|
|
2249
|
-
this.wallets[entity.id] = __spreadValues(__spreadValues({}, entityToWallet(entity)), this.wallets[entity.id]);
|
|
2250
|
-
}
|
|
2251
|
-
});
|
|
2252
|
-
yield this.setWallets(this.wallets);
|
|
2253
|
-
});
|
|
2254
|
-
}
|
|
2255
|
-
/**
|
|
2256
|
-
* Resend a verification email for the current user.
|
|
2257
|
-
*/
|
|
2258
|
-
resendVerificationCode() {
|
|
2259
|
-
return __async(this, null, function* () {
|
|
2260
|
-
yield this.ctx.client.resendVerificationCode(__spreadValues({
|
|
2261
|
-
userId: this.userId
|
|
2262
|
-
}, this.getVerificationEmailProps()));
|
|
2263
|
-
});
|
|
2264
|
-
}
|
|
2265
|
-
/**
|
|
2266
|
-
* Checks if the current session is active.
|
|
2267
|
-
* @returns `true` if active, `false` otherwise
|
|
2268
|
-
*/
|
|
2269
|
-
isSessionActive() {
|
|
2270
|
-
return __async(this, null, function* () {
|
|
2271
|
-
if (this.externalWalletConnectionType === "CONNECTION_ONLY") {
|
|
2272
|
-
return true;
|
|
2273
|
-
}
|
|
2274
|
-
const { isAuthenticated } = yield this.touchSession();
|
|
2275
|
-
return !!isAuthenticated;
|
|
2276
|
-
});
|
|
2277
|
-
}
|
|
2278
|
-
/**
|
|
2279
|
-
* Checks if a session is active and a wallet exists.
|
|
2280
|
-
* @returns `true` if active, `false` otherwise
|
|
2281
|
-
**/
|
|
2282
|
-
isFullyLoggedIn() {
|
|
2283
|
-
return __async(this, null, function* () {
|
|
2284
|
-
if (this.externalWalletConnectionType === "CONNECTION_ONLY") {
|
|
2285
|
-
return true;
|
|
2286
|
-
}
|
|
2287
|
-
const isSessionActive = yield this.isSessionActive();
|
|
2288
|
-
return isSessionActive && this.currentWalletIdsArray.length > 0 && this.currentWalletIdsArray.reduce((acc, [id]) => acc && !!this.wallets[id], true);
|
|
2289
|
-
});
|
|
2290
|
-
}
|
|
2291
|
-
supportedAuthMethods(auth) {
|
|
2292
|
-
return __async(this, null, function* () {
|
|
2293
|
-
const { supportedAuthMethods } = yield this.ctx.client.getSupportedAuthMethods(auth);
|
|
2294
|
-
const authMethods = /* @__PURE__ */ new Set();
|
|
2295
|
-
for (const type of supportedAuthMethods) {
|
|
2296
|
-
switch (type) {
|
|
2297
|
-
case "PASSWORD":
|
|
2298
|
-
authMethods.add(AuthMethod.PASSWORD);
|
|
2299
|
-
break;
|
|
2300
|
-
case "BIOMETRIC":
|
|
2301
|
-
authMethods.add(AuthMethod.PASSKEY);
|
|
2302
|
-
break;
|
|
2303
|
-
}
|
|
2304
|
-
}
|
|
2305
|
-
return authMethods;
|
|
2306
|
-
});
|
|
2307
|
-
}
|
|
2308
|
-
/**
|
|
2309
|
-
* Get hints associated with the users stored biometrics.
|
|
2310
|
-
* @deprecated
|
|
2311
|
-
* @returns Array containing useragents and AAGuids for stored biometrics
|
|
2312
|
-
*/
|
|
2313
|
-
getUserBiometricLocationHints() {
|
|
2314
|
-
return __async(this, null, function* () {
|
|
2315
|
-
const { auth } = this.assertIsAuthSet();
|
|
2316
|
-
return yield this.ctx.client.getBiometricLocationHints(auth);
|
|
2317
|
-
});
|
|
2318
|
-
}
|
|
2319
|
-
/**
|
|
2320
|
-
* Updates the session with the user management server, possibly
|
|
2321
|
-
* opening a popup to refresh the session.
|
|
2322
|
-
*
|
|
2323
|
-
* @param {Object} opts the options object.
|
|
2324
|
-
* @param {boolean} [shouldOpenPopup] - if `true`, the running device will open a popup to reauthenticate the user.
|
|
2325
|
-
* @returns a URL for the user to reauthenticate.
|
|
2326
|
-
**/
|
|
2327
|
-
refreshSession() {
|
|
2328
|
-
return __async(this, arguments, function* ({
|
|
2329
|
-
shouldOpenPopup = false
|
|
2330
|
-
} = {}) {
|
|
2331
|
-
const { sessionId } = yield this.touchSession(true);
|
|
2332
|
-
if (!this.loginEncryptionKeyPair) {
|
|
2333
|
-
yield this.setLoginEncryptionKeyPair();
|
|
2334
|
-
}
|
|
2335
|
-
const link = yield this.getLoginUrl({
|
|
2336
|
-
sessionId
|
|
2337
|
-
});
|
|
2338
|
-
if (shouldOpenPopup) {
|
|
2339
|
-
this.platformUtils.openPopup(link);
|
|
2340
|
-
}
|
|
2341
|
-
return link;
|
|
2342
|
-
});
|
|
2343
|
-
}
|
|
2344
|
-
/**
|
|
2345
|
-
* Call this method after login to ensure that the user ID is set
|
|
2346
|
-
* internally.
|
|
2347
|
-
**/
|
|
2348
|
-
userSetupAfterLogin() {
|
|
2349
|
-
return __async(this, null, function* () {
|
|
2350
|
-
const session = yield this.touchSession();
|
|
2351
|
-
yield this.setUserId(session.userId);
|
|
2352
|
-
if (session.currentWalletIds && session.currentWalletIds !== this.currentWalletIds)
|
|
2353
|
-
yield this.setCurrentWalletIds(session.currentWalletIds, {
|
|
2354
|
-
sessionLookupId: this.isPortal() ? session.sessionLookupId : void 0
|
|
2355
|
-
});
|
|
2356
|
-
return session;
|
|
2357
|
-
});
|
|
2358
|
-
}
|
|
2359
|
-
/**
|
|
2360
|
-
* Get transmission shares associated with session.
|
|
2361
|
-
* @param {Object} opts the options object.
|
|
2362
|
-
* @param {boolean} opts.isForNewDevice - true if this device is registering.
|
|
2363
|
-
* @returns - transmission keyshares.
|
|
2364
|
-
**/
|
|
2365
|
-
getTransmissionKeyShares() {
|
|
2366
|
-
return __async(this, arguments, function* ({ isForNewDevice = false } = {}) {
|
|
2367
|
-
const session = yield this.touchSession();
|
|
2368
|
-
const sessionLookupId = isForNewDevice ? `${session.sessionLookupId}-new-device` : session.sessionLookupId;
|
|
2369
|
-
return this.ctx.client.getTransmissionKeyshares(this.userId, sessionLookupId);
|
|
2370
|
-
});
|
|
2371
|
-
}
|
|
2372
|
-
/**
|
|
2373
|
-
* Call this method after login to perform setup.
|
|
2374
|
-
* @param {Object} opts the options object.
|
|
2375
|
-
* @param {any[]} opts.temporaryShares optional temporary shares to use for decryption.
|
|
2376
|
-
* @param {boolean} [opts.skipSessionRefresh] - whether or not to skip refreshing the session.
|
|
2377
|
-
**/
|
|
2378
|
-
setupAfterLogin() {
|
|
2379
|
-
return __async(this, arguments, function* ({
|
|
2380
|
-
temporaryShares,
|
|
2381
|
-
skipSessionRefresh = false
|
|
2382
|
-
} = {}) {
|
|
2383
|
-
if (!temporaryShares) {
|
|
2384
|
-
temporaryShares = (yield this.getTransmissionKeyShares()).data.temporaryShares;
|
|
2385
|
-
}
|
|
2386
|
-
temporaryShares.forEach((share) => {
|
|
2387
|
-
const signer = decryptWithPrivateKey(this.loginEncryptionKeyPair.privateKey, share.encryptedShare, share.encryptedKey);
|
|
2388
|
-
this.wallets[share.walletId] = {
|
|
2389
|
-
id: share.walletId,
|
|
2390
|
-
signer
|
|
2391
|
-
};
|
|
2392
|
-
});
|
|
2393
|
-
yield this.deleteLoginEncryptionKeyPair();
|
|
2394
|
-
yield this.populateWalletAddresses();
|
|
2395
|
-
yield this.touchSession(!skipSessionRefresh);
|
|
2396
|
-
});
|
|
2397
|
-
}
|
|
2398
|
-
/**
|
|
2399
|
-
* Distributes a new wallet recovery share.
|
|
2400
|
-
* @param {Object} opts the options object.
|
|
2401
|
-
* @param {string} opts.walletId the wallet to distribute the recovery share for.
|
|
2402
|
-
* @param {string} opts.userShare optional user share generate the recovery share from. Defaults to the signer from the passed in walletId
|
|
2403
|
-
* @param {boolean} opts.skipBiometricShareCreation whether or not to skip biometric share creation. Used when regenerating recovery shares.
|
|
2404
|
-
* @param {boolean} opts.forceRefreshRecovery whether or not to force recovery secret regeneration. Used when regenerating recovery shares.
|
|
2405
|
-
* @returns {string} the recovery share.
|
|
2406
|
-
**/
|
|
2407
|
-
distributeNewWalletShare(_0) {
|
|
2408
|
-
return __async(this, arguments, function* ({
|
|
2409
|
-
walletId,
|
|
2410
|
-
userShare,
|
|
2411
|
-
skipBiometricShareCreation = false,
|
|
2412
|
-
forceRefresh = false
|
|
2413
|
-
}) {
|
|
2414
|
-
let userSigner = userShare;
|
|
2415
|
-
if (!userSigner) {
|
|
2416
|
-
userSigner = this.wallets[walletId].signer;
|
|
2417
|
-
}
|
|
2418
|
-
const recoveryShare = skipBiometricShareCreation ? yield sendRecoveryForShare({
|
|
2419
|
-
ctx: this.ctx,
|
|
2420
|
-
userId: this.userId,
|
|
2421
|
-
walletId,
|
|
2422
|
-
userSigner,
|
|
2423
|
-
emailProps: this.getBackupKitEmailProps(),
|
|
2424
|
-
forceRefresh
|
|
2425
|
-
}) : yield distributeNewShare({
|
|
2426
|
-
ctx: this.ctx,
|
|
2427
|
-
userId: this.userId,
|
|
2428
|
-
walletId,
|
|
2429
|
-
userShare: userSigner,
|
|
2430
|
-
emailProps: this.getBackupKitEmailProps()
|
|
2431
|
-
});
|
|
2432
|
-
return recoveryShare;
|
|
2433
|
-
});
|
|
2434
|
-
}
|
|
2435
|
-
waitForWalletAddress(walletId) {
|
|
2436
|
-
return __async(this, null, function* () {
|
|
2437
|
-
let maxPolls = 0;
|
|
2438
|
-
while (true) {
|
|
2439
|
-
try {
|
|
2440
|
-
if (maxPolls === 10) {
|
|
2441
|
-
break;
|
|
2442
|
-
}
|
|
2443
|
-
++maxPolls;
|
|
2444
|
-
const res = yield this.ctx.client.getWallets(this.userId);
|
|
2445
|
-
const wallet = res.data.wallets.find((w) => w.id === walletId);
|
|
2446
|
-
if (wallet && wallet.address) {
|
|
2447
|
-
return;
|
|
2448
|
-
}
|
|
2449
|
-
yield new Promise((resolve) => setTimeout(resolve, SHORT_POLLING_INTERVAL_MS));
|
|
2450
|
-
} catch (err) {
|
|
2451
|
-
console.error(err);
|
|
2452
|
-
}
|
|
2453
|
-
}
|
|
2454
|
-
throw new Error("timed out waiting for wallet address");
|
|
2455
|
-
});
|
|
2456
|
-
}
|
|
2457
|
-
/**
|
|
2458
|
-
* Waits for a pregen wallet address to be created.
|
|
2459
|
-
*
|
|
2460
|
-
* @param pregenIdentifier - the identifier of the user the pregen wallet is associated with.
|
|
2461
|
-
* @param walletId - the wallet id
|
|
2462
|
-
* @param pregenIdentifierType - the identifier type of the user the pregen wallet is associated with.
|
|
2463
|
-
* @returns - recovery share.
|
|
2464
|
-
**/
|
|
2465
|
-
waitForPregenWalletAddress(walletId) {
|
|
2466
|
-
return __async(this, null, function* () {
|
|
2467
|
-
let maxPolls = 0;
|
|
2468
|
-
while (true) {
|
|
2469
|
-
try {
|
|
2470
|
-
if (maxPolls === 10) {
|
|
2471
|
-
break;
|
|
2472
|
-
}
|
|
2473
|
-
++maxPolls;
|
|
2474
|
-
const res = yield this.getPregenWallets();
|
|
2475
|
-
const wallet = res.find((w) => w.id === walletId);
|
|
2476
|
-
if (wallet && wallet.address) {
|
|
2477
|
-
return;
|
|
2478
|
-
}
|
|
2479
|
-
yield new Promise((resolve) => setTimeout(resolve, SHORT_POLLING_INTERVAL_MS));
|
|
2480
|
-
} catch (err) {
|
|
2481
|
-
console.error(err);
|
|
2482
|
-
}
|
|
2483
|
-
}
|
|
2484
|
-
throw new Error("timed out waiting for wallet address");
|
|
2485
|
-
});
|
|
2486
|
-
}
|
|
2487
|
-
/**
|
|
2488
|
-
* Creates several new wallets with the desired types. If no types are provided, this method
|
|
2489
|
-
* will create one for each of the non-optional types specified in the instance's `supportedWalletTypes`
|
|
2490
|
-
* object that are not already present. This is automatically called upon account creation to ensure that
|
|
2491
|
-
* the user has a wallet of each required type.
|
|
2492
|
-
*
|
|
2493
|
-
* @param {Object} [opts] the options object.
|
|
2494
|
-
* @param {boolean} [opts.skipDistribute] if `true`, the wallets' recovery share will not be distributed.
|
|
2495
|
-
* @param {WalletType[]} [opts.types] the types of wallets to create.
|
|
2496
|
-
* @returns {Object} the wallets created, their ids, and the recovery secret.
|
|
2497
|
-
**/
|
|
2498
|
-
createWalletPerType() {
|
|
2499
|
-
return __async(this, arguments, function* ({
|
|
2500
|
-
skipDistribute = false,
|
|
2501
|
-
types
|
|
2502
|
-
} = {}) {
|
|
2503
|
-
const wallets = [];
|
|
2504
|
-
const walletIds = {};
|
|
2505
|
-
let recoverySecret;
|
|
2506
|
-
for (const type of yield this.getTypesToCreate(types)) {
|
|
2507
|
-
const [wallet, recoveryShare] = yield this.createWallet({ type, skipDistribute });
|
|
2508
|
-
wallets.push(wallet);
|
|
2509
|
-
getEquivalentTypes(type).filter((t) => !!this.isWalletTypeEnabled[t]).forEach((t) => {
|
|
2510
|
-
walletIds[t] = [wallet.id];
|
|
2511
|
-
});
|
|
2512
|
-
if (recoveryShare) {
|
|
2513
|
-
recoverySecret = recoveryShare;
|
|
2514
|
-
}
|
|
2515
|
-
}
|
|
2516
|
-
return { wallets, walletIds, recoverySecret };
|
|
2517
|
-
});
|
|
2518
|
-
}
|
|
2519
|
-
/**
|
|
2520
|
-
* Refresh the current user share for a wallet.
|
|
2521
|
-
*
|
|
2522
|
-
* @param {Object} opts the options object.
|
|
2523
|
-
* @param {string} opts.walletId the wallet id to refresh.
|
|
2524
|
-
* @param {string} opts.share the current user share.
|
|
2525
|
-
* @param {string} [opts.oldPartnerId] the current partner id.
|
|
2526
|
-
* @param {string} [opts.newPartnerId] the new partner id to set, if any.
|
|
2527
|
-
* @param {string} [opts.keyShareProtocolId]
|
|
2528
|
-
* @param {boolean} [opts.redistributeBackupEncryptedShares] whether or not to redistribute backup encrypted shares.
|
|
2529
|
-
* @returns {Object} the new user share and recovery secret.
|
|
2530
|
-
**/
|
|
2531
|
-
refreshShare(_0) {
|
|
2532
|
-
return __async(this, arguments, function* ({
|
|
2533
|
-
walletId,
|
|
2534
|
-
share,
|
|
2535
|
-
oldPartnerId,
|
|
2536
|
-
newPartnerId,
|
|
2537
|
-
keyShareProtocolId,
|
|
2538
|
-
redistributeBackupEncryptedShares
|
|
2539
|
-
}) {
|
|
2540
|
-
const { signer, protocolId } = yield this.platformUtils.refresh(
|
|
2541
|
-
this.ctx,
|
|
2542
|
-
this.retrieveSessionCookie(),
|
|
2543
|
-
this.userId,
|
|
2544
|
-
walletId,
|
|
2545
|
-
share,
|
|
2546
|
-
oldPartnerId,
|
|
2547
|
-
newPartnerId,
|
|
2548
|
-
keyShareProtocolId
|
|
2549
|
-
);
|
|
2550
|
-
const recoverySecret = yield distributeNewShare({
|
|
2551
|
-
ctx: this.ctx,
|
|
2552
|
-
userId: this.userId,
|
|
2553
|
-
walletId,
|
|
2554
|
-
userShare: signer,
|
|
2555
|
-
ignoreRedistributingBackupEncryptedShare: !redistributeBackupEncryptedShares,
|
|
2556
|
-
emailProps: this.getBackupKitEmailProps(),
|
|
2557
|
-
partnerId: newPartnerId,
|
|
2558
|
-
protocolId
|
|
2559
|
-
});
|
|
2560
|
-
return { signer, recoverySecret, protocolId };
|
|
2561
|
-
});
|
|
2562
|
-
}
|
|
2563
|
-
/**
|
|
2564
|
-
* Creates a new wallet.
|
|
2565
|
-
* @param {Object} opts the options object.
|
|
2566
|
-
* @param {WalletType} opts.type the type of wallet to create.
|
|
2567
|
-
* @param {boolean} opts.skipDistribute - if true, recovery share will not be distributed.
|
|
2568
|
-
* @returns {[Wallet, string | null]} `[wallet, recoveryShare]` - the wallet object and the new recovery share.
|
|
2569
|
-
**/
|
|
2570
|
-
createWallet() {
|
|
2571
|
-
return __async(this, arguments, function* ({
|
|
2572
|
-
type: _type,
|
|
2573
|
-
skipDistribute = false
|
|
2574
|
-
} = {}) {
|
|
2575
|
-
var _a, _b;
|
|
2576
|
-
this.requireApiKey();
|
|
2577
|
-
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2578
|
-
const walletType = yield this.assertIsValidWalletType(
|
|
2579
|
-
_type != null ? _type : (_a = supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type
|
|
2580
|
-
);
|
|
2581
|
-
let signer;
|
|
2582
|
-
let wallet;
|
|
2583
|
-
let keygenRes;
|
|
2584
|
-
switch (walletType) {
|
|
2585
|
-
case WalletType2.SOLANA: {
|
|
2586
|
-
keygenRes = yield this.platformUtils.ed25519Keygen(
|
|
2587
|
-
this.ctx,
|
|
2588
|
-
this.userId,
|
|
2589
|
-
this.retrieveSessionCookie(),
|
|
2590
|
-
this.getBackupKitEmailProps()
|
|
2591
|
-
);
|
|
2592
|
-
break;
|
|
2593
|
-
}
|
|
2594
|
-
default: {
|
|
2595
|
-
keygenRes = yield this.platformUtils.keygen(
|
|
2596
|
-
this.ctx,
|
|
2597
|
-
this.userId,
|
|
2598
|
-
walletType,
|
|
2599
|
-
null,
|
|
2600
|
-
this.retrieveSessionCookie(),
|
|
2601
|
-
this.getBackupKitEmailProps()
|
|
2602
|
-
);
|
|
2603
|
-
break;
|
|
2604
|
-
}
|
|
2605
|
-
}
|
|
2606
|
-
const walletId = keygenRes.walletId;
|
|
2607
|
-
signer = keygenRes.signer;
|
|
2608
|
-
this.wallets[walletId] = {
|
|
2609
|
-
id: walletId,
|
|
2610
|
-
signer,
|
|
2611
|
-
scheme: walletType === WalletType2.SOLANA ? WalletScheme2.ED25519 : WalletScheme2.DKLS,
|
|
2612
|
-
type: walletType
|
|
2613
|
-
};
|
|
2614
|
-
wallet = this.wallets[walletId];
|
|
2615
|
-
yield this.waitForWalletAddress(wallet.id);
|
|
2616
|
-
yield this.populateWalletAddresses();
|
|
2617
|
-
let recoveryShare = null;
|
|
2618
|
-
if (!skipDistribute) {
|
|
2619
|
-
recoveryShare = yield distributeNewShare({
|
|
2620
|
-
ctx: this.ctx,
|
|
2621
|
-
userId: this.userId,
|
|
2622
|
-
walletId: wallet.id,
|
|
2623
|
-
userShare: signer,
|
|
2624
|
-
emailProps: this.getBackupKitEmailProps()
|
|
2625
|
-
});
|
|
2626
|
-
}
|
|
2627
|
-
yield this.setCurrentWalletIds(__spreadProps(__spreadValues({}, this.currentWalletIds), {
|
|
2628
|
-
[walletType]: [.../* @__PURE__ */ new Set([...(_b = this.currentWalletIds[walletType]) != null ? _b : [], walletId])]
|
|
2629
|
-
}));
|
|
2630
|
-
const walletNoSigner = __spreadValues({}, wallet);
|
|
2631
|
-
delete walletNoSigner.signer;
|
|
2632
|
-
dispatchEvent(ParaEvent.WALLET_CREATED, {
|
|
2633
|
-
wallet: walletNoSigner,
|
|
2634
|
-
recoverySecret: recoveryShare
|
|
2635
|
-
});
|
|
2636
|
-
return [wallet, recoveryShare];
|
|
2637
|
-
});
|
|
2638
|
-
}
|
|
2639
|
-
encodeWalletBase64(wallet) {
|
|
2640
|
-
const walletJson = JSON.stringify(wallet);
|
|
2641
|
-
const base64Wallet = Buffer.from(walletJson).toString("base64");
|
|
2642
|
-
return base64Wallet;
|
|
2643
|
-
}
|
|
2644
|
-
/**
|
|
2645
|
-
* Encodes the current wallets encoded in Base 64.
|
|
2646
|
-
* @returns {string} the encoded wallet string
|
|
2647
|
-
**/
|
|
2648
|
-
getUserShare() {
|
|
2649
|
-
if (Object.values(this.wallets).length === 0) {
|
|
2650
|
-
return null;
|
|
2651
|
-
}
|
|
2652
|
-
return Object.values(this.wallets).map((wallet) => this.encodeWalletBase64(wallet)).join("-");
|
|
2653
|
-
}
|
|
2654
|
-
/**
|
|
2655
|
-
* Sets the current wallets from a Base 64 string.
|
|
2656
|
-
* @param {string} base64Wallet the encoded wallet string
|
|
2657
|
-
**/
|
|
2658
|
-
setUserShare(base64Wallets) {
|
|
2659
|
-
return __async(this, null, function* () {
|
|
2660
|
-
if (!base64Wallets) {
|
|
2661
|
-
return;
|
|
2662
|
-
}
|
|
2663
|
-
const base64WalletsSplit = base64Wallets.split("-");
|
|
2664
|
-
for (const base64Wallet of base64WalletsSplit) {
|
|
2665
|
-
const walletJson = Buffer.from(base64Wallet, "base64").toString();
|
|
2666
|
-
const wallet = migrateWallet(JSON.parse(walletJson));
|
|
2667
|
-
this.wallets[wallet.id] = wallet;
|
|
2668
|
-
yield this.setWallets(this.wallets);
|
|
2669
|
-
}
|
|
2670
|
-
});
|
|
2671
|
-
}
|
|
2672
|
-
getTransactionReviewUrl(transactionId, timeoutMs) {
|
|
2673
|
-
return __async(this, null, function* () {
|
|
2674
|
-
return this.constructPortalUrl("txReview", {
|
|
2675
|
-
pathId: transactionId,
|
|
2676
|
-
params: {
|
|
2677
|
-
email: this.email,
|
|
2678
|
-
timeoutMs: timeoutMs == null ? void 0 : timeoutMs.toString()
|
|
2679
|
-
}
|
|
2680
|
-
});
|
|
2681
|
-
});
|
|
2682
|
-
}
|
|
2683
|
-
getOnRampTransactionUrl(_a) {
|
|
2684
|
-
return __async(this, null, function* () {
|
|
2685
|
-
var _b = _a, {
|
|
2686
|
-
purchaseId,
|
|
2687
|
-
providerKey
|
|
2688
|
-
} = _b, walletParams = __objRest(_b, [
|
|
2689
|
-
"purchaseId",
|
|
2690
|
-
"providerKey"
|
|
2691
|
-
]);
|
|
2692
|
-
const { sessionId } = yield this.touchSession();
|
|
2693
|
-
const [key, identifier] = extractWalletRef(walletParams);
|
|
2694
|
-
return this.constructPortalUrl("onRamp", {
|
|
2695
|
-
pathId: purchaseId,
|
|
2696
|
-
sessionId,
|
|
2697
|
-
params: {
|
|
2698
|
-
[key]: identifier,
|
|
2699
|
-
providerKey,
|
|
2700
|
-
currentWalletIds: JSON.stringify(this.currentWalletIds)
|
|
2701
|
-
}
|
|
2702
|
-
});
|
|
2703
|
-
});
|
|
2704
|
-
}
|
|
2705
|
-
/**
|
|
2706
|
-
* Signs a message using one of the current wallets.
|
|
2707
|
-
*
|
|
2708
|
-
* If you want to sign the keccak256 hash of a message, hash the
|
|
2709
|
-
* message first and then pass in the base64 encoded hash.
|
|
2710
|
-
* @param {Object} opts the options object.
|
|
2711
|
-
* @param {string} opts.walletId the id of the wallet to sign with.
|
|
2712
|
-
* @param {string} opts.messageBase64 the base64 encoding of exact message that should be signed
|
|
2713
|
-
* @param {number} [opts.timeout] optional timeout in milliseconds. If not present, defaults to 30 seconds.
|
|
2714
|
-
* @param {string} [opts.cosmosSignDocBase64] the Cosmos `SignDoc` in base64, if applicable
|
|
2715
|
-
**/
|
|
2716
|
-
signMessage(_0) {
|
|
2717
|
-
return __async(this, arguments, function* ({
|
|
2718
|
-
walletId,
|
|
2719
|
-
messageBase64,
|
|
2720
|
-
timeoutMs = 3e4,
|
|
2721
|
-
cosmosSignDocBase64,
|
|
2722
|
-
isCanceled = () => false,
|
|
2723
|
-
onCancel,
|
|
2724
|
-
onPoll
|
|
2725
|
-
}) {
|
|
2726
|
-
this.assertIsValidWalletId(walletId);
|
|
2727
|
-
const wallet = this.wallets[walletId];
|
|
2728
|
-
let signerId = this.userId;
|
|
2729
|
-
if (wallet.partnerId && !wallet.userId) {
|
|
2730
|
-
signerId = wallet.partnerId;
|
|
2731
|
-
}
|
|
2732
|
-
let signRes = yield this.signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64 });
|
|
2733
|
-
let timeStart = Date.now();
|
|
2734
|
-
if (signRes.pendingTransactionId) {
|
|
2735
|
-
this.platformUtils.openPopup(
|
|
2736
|
-
yield this.getTransactionReviewUrl(signRes.pendingTransactionId, timeoutMs),
|
|
2737
|
-
{ type: cosmosSignDocBase64 ? "SIGN_TRANSACTION_REVIEW" /* SIGN_TRANSACTION_REVIEW */ : "SIGN_MESSAGE_REVIEW" /* SIGN_MESSAGE_REVIEW */ }
|
|
2738
|
-
);
|
|
2739
|
-
} else {
|
|
2740
|
-
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes);
|
|
2741
|
-
return signRes;
|
|
2742
|
-
}
|
|
2743
|
-
while (true) {
|
|
2744
|
-
if (isCanceled() || Date.now() - timeStart > timeoutMs) {
|
|
2745
|
-
onCancel == null ? void 0 : onCancel();
|
|
2746
|
-
break;
|
|
2747
|
-
}
|
|
2748
|
-
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
2749
|
-
try {
|
|
2750
|
-
yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
|
|
2751
|
-
} catch (err) {
|
|
2752
|
-
const error = new TransactionReviewDenied();
|
|
2753
|
-
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes, error.message);
|
|
2754
|
-
throw error;
|
|
2755
|
-
}
|
|
2756
|
-
signRes = yield this.signMessageInner({ wallet, signerId, messageBase64, cosmosSignDocBase64 });
|
|
2757
|
-
if (signRes.pendingTransactionId) {
|
|
2758
|
-
onPoll == null ? void 0 : onPoll();
|
|
2759
|
-
continue;
|
|
2760
|
-
} else {
|
|
2761
|
-
break;
|
|
2762
|
-
}
|
|
2763
|
-
}
|
|
2764
|
-
if (signRes.pendingTransactionId) {
|
|
2765
|
-
const error = new TransactionReviewTimeout(
|
|
2766
|
-
yield this.getTransactionReviewUrl(signRes.pendingTransactionId),
|
|
2767
|
-
signRes.pendingTransactionId
|
|
2768
|
-
);
|
|
2769
|
-
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes, error.message);
|
|
2770
|
-
throw error;
|
|
2771
|
-
}
|
|
2772
|
-
dispatchEvent(ParaEvent.SIGN_MESSAGE_EVENT, signRes);
|
|
2773
|
-
return signRes;
|
|
2774
|
-
});
|
|
2775
|
-
}
|
|
2776
|
-
signMessageInner(_0) {
|
|
2777
|
-
return __async(this, arguments, function* ({
|
|
2778
|
-
wallet,
|
|
2779
|
-
signerId,
|
|
2780
|
-
messageBase64,
|
|
2781
|
-
cosmosSignDocBase64
|
|
2782
|
-
}) {
|
|
2783
|
-
let signRes;
|
|
2784
|
-
switch (wallet.scheme) {
|
|
2785
|
-
case WalletScheme2.ED25519:
|
|
2786
|
-
signRes = yield this.platformUtils.ed25519Sign(
|
|
2787
|
-
this.ctx,
|
|
2788
|
-
signerId,
|
|
2789
|
-
wallet.id,
|
|
2790
|
-
wallet.signer,
|
|
2791
|
-
messageBase64,
|
|
2792
|
-
this.retrieveSessionCookie()
|
|
2793
|
-
);
|
|
2794
|
-
break;
|
|
2795
|
-
default:
|
|
2796
|
-
signRes = yield this.platformUtils.signMessage(
|
|
2797
|
-
this.ctx,
|
|
2798
|
-
signerId,
|
|
2799
|
-
wallet.id,
|
|
2800
|
-
wallet.signer,
|
|
2801
|
-
messageBase64,
|
|
2802
|
-
this.retrieveSessionCookie(),
|
|
2803
|
-
wallet.scheme === WalletScheme2.DKLS,
|
|
2804
|
-
cosmosSignDocBase64
|
|
2805
|
-
);
|
|
2806
|
-
break;
|
|
2807
|
-
}
|
|
2808
|
-
return signRes;
|
|
2809
|
-
});
|
|
2810
|
-
}
|
|
2811
|
-
/**
|
|
2812
|
-
* Signs a transaction.
|
|
2813
|
-
* @param {Object} opts the options object.
|
|
2814
|
-
* @param {string} opts.walletId the id of the wallet to sign with.
|
|
2815
|
-
* @param {string} opts.rlpEncodedTxBase64 the transaction to sign, in RLP base64 encoding
|
|
2816
|
-
* @param {string} [opts.chainId] the EVM chain id of the chain the transaction is being sent on, if applicable
|
|
2817
|
-
* @param {number} [opts.timeoutMs] the amount of time to wait for the user to sign the transaction, in milliseconds
|
|
2818
|
-
**/
|
|
2819
|
-
signTransaction(_0) {
|
|
2820
|
-
return __async(this, arguments, function* ({
|
|
2821
|
-
walletId,
|
|
2822
|
-
rlpEncodedTxBase64,
|
|
2823
|
-
chainId,
|
|
2824
|
-
timeoutMs = 3e4,
|
|
2825
|
-
isCanceled = () => false,
|
|
2826
|
-
onCancel,
|
|
2827
|
-
onPoll
|
|
2828
|
-
}) {
|
|
2829
|
-
this.assertIsValidWalletId(walletId);
|
|
2830
|
-
const wallet = this.wallets[walletId];
|
|
2831
|
-
let signerId = this.userId;
|
|
2832
|
-
if (wallet.partnerId && !wallet.userId) {
|
|
2833
|
-
signerId = wallet.partnerId;
|
|
2834
|
-
}
|
|
2835
|
-
let signRes = yield this.platformUtils.signTransaction(
|
|
2836
|
-
this.ctx,
|
|
2837
|
-
signerId,
|
|
2838
|
-
walletId,
|
|
2839
|
-
this.wallets[walletId].signer,
|
|
2840
|
-
rlpEncodedTxBase64,
|
|
2841
|
-
chainId,
|
|
2842
|
-
this.retrieveSessionCookie(),
|
|
2843
|
-
wallet.scheme === WalletScheme2.DKLS
|
|
2844
|
-
);
|
|
2845
|
-
let timeStart = Date.now();
|
|
2846
|
-
if (signRes.pendingTransactionId) {
|
|
2847
|
-
this.platformUtils.openPopup(
|
|
2848
|
-
yield this.getTransactionReviewUrl(signRes.pendingTransactionId, timeoutMs),
|
|
2849
|
-
{ type: "SIGN_TRANSACTION_REVIEW" /* SIGN_TRANSACTION_REVIEW */ }
|
|
2850
|
-
);
|
|
2851
|
-
} else {
|
|
2852
|
-
dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes);
|
|
2853
|
-
return signRes;
|
|
2854
|
-
}
|
|
2855
|
-
while (true) {
|
|
2856
|
-
if (isCanceled() || Date.now() - timeStart > timeoutMs) {
|
|
2857
|
-
onCancel == null ? void 0 : onCancel();
|
|
2858
|
-
break;
|
|
2859
|
-
}
|
|
2860
|
-
yield new Promise((resolve) => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
2861
|
-
try {
|
|
2862
|
-
yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId);
|
|
2863
|
-
} catch (err) {
|
|
2864
|
-
const error = new TransactionReviewDenied();
|
|
2865
|
-
dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes, error.message);
|
|
2866
|
-
throw error;
|
|
2867
|
-
}
|
|
2868
|
-
signRes = yield this.platformUtils.signTransaction(
|
|
2869
|
-
this.ctx,
|
|
2870
|
-
signerId,
|
|
2871
|
-
walletId,
|
|
2872
|
-
this.wallets[walletId].signer,
|
|
2873
|
-
rlpEncodedTxBase64,
|
|
2874
|
-
chainId,
|
|
2875
|
-
this.retrieveSessionCookie(),
|
|
2876
|
-
wallet.scheme === WalletScheme2.DKLS
|
|
2877
|
-
);
|
|
2878
|
-
if (signRes.pendingTransactionId) {
|
|
2879
|
-
onPoll == null ? void 0 : onPoll();
|
|
2880
|
-
continue;
|
|
2881
|
-
} else {
|
|
2882
|
-
break;
|
|
2883
|
-
}
|
|
2884
|
-
}
|
|
2885
|
-
if (signRes.pendingTransactionId) {
|
|
2886
|
-
const error = new TransactionReviewTimeout(
|
|
2887
|
-
yield this.getTransactionReviewUrl(signRes.pendingTransactionId),
|
|
2888
|
-
signRes.pendingTransactionId
|
|
2889
|
-
);
|
|
2890
|
-
dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes, error.message);
|
|
2891
|
-
throw error;
|
|
2892
|
-
}
|
|
2893
|
-
dispatchEvent(ParaEvent.SIGN_TRANSACTION_EVENT, signRes);
|
|
2894
|
-
return signRes;
|
|
2895
|
-
});
|
|
2896
|
-
}
|
|
2897
|
-
isProviderModalDisabled() {
|
|
2898
|
-
return !!this.disableProviderModal;
|
|
2899
|
-
}
|
|
2900
|
-
/**
|
|
2901
|
-
* Starts a on-ramp or off-ramp transaction and returns the Para Portal link for the user to finalize and complete it.
|
|
2902
|
-
* @param {Object} opts the options object
|
|
2903
|
-
* @param {OnRampPurchaseCreateParams} opts.params the transaction settings.
|
|
2904
|
-
* @param {boolean} opts.shouldOpenPopup if `true`, a popup window with the link will be opened.
|
|
2905
|
-
* @param {string} opts.walletId the wallet ID to use for the transaction, where funds will be sent or withdrawn.
|
|
2906
|
-
* @param {string} opts.externalWalletAddress the external wallet address to send funds to or withdraw funds from, if using an external wallet.
|
|
2907
|
-
**/
|
|
2908
|
-
initiateOnRampTransaction(options) {
|
|
2909
|
-
return __async(this, null, function* () {
|
|
2910
|
-
var _b;
|
|
2911
|
-
const _a = options, { params, shouldOpenPopup } = _a, walletParams = __objRest(_a, ["params", "shouldOpenPopup"]);
|
|
2912
|
-
const onRampPurchase = yield this.ctx.client.createOnRampPurchase(__spreadValues({
|
|
2913
|
-
userId: this.userId,
|
|
2914
|
-
params: __spreadProps(__spreadValues({}, params), {
|
|
2915
|
-
address: (_b = walletParams.externalWalletAddress) != null ? _b : this.getDisplayAddress(walletParams.walletId, { addressType: params.walletType })
|
|
2916
|
-
})
|
|
2917
|
-
}, walletParams));
|
|
2918
|
-
const portalUrl = yield this.getOnRampTransactionUrl(__spreadValues({
|
|
2919
|
-
purchaseId: onRampPurchase.id,
|
|
2920
|
-
providerKey: onRampPurchase.providerKey
|
|
2921
|
-
}, walletParams));
|
|
2922
|
-
if (shouldOpenPopup) {
|
|
2923
|
-
this.platformUtils.openPopup(portalUrl, { type: "ON_RAMP_TRANSACTION" /* ON_RAMP_TRANSACTION */ });
|
|
2924
|
-
}
|
|
2925
|
-
return { onRampPurchase, portalUrl };
|
|
2926
|
-
});
|
|
2927
|
-
}
|
|
2928
|
-
/**
|
|
2929
|
-
* Returns `true` if session was successfully kept alive, `false` otherwise.
|
|
2930
|
-
**/
|
|
2931
|
-
keepSessionAlive() {
|
|
2932
|
-
return __async(this, null, function* () {
|
|
2933
|
-
try {
|
|
2934
|
-
yield this.ctx.client.keepSessionAlive(this.userId);
|
|
2935
|
-
return true;
|
|
2936
|
-
} catch (err) {
|
|
2937
|
-
return false;
|
|
2938
|
-
}
|
|
2939
|
-
});
|
|
2940
|
-
}
|
|
2941
|
-
/**
|
|
2942
|
-
* Serialize the current session for import by another Para instance.
|
|
2943
|
-
* @returns {string} the serialized session
|
|
2944
|
-
*/
|
|
2945
|
-
exportSession() {
|
|
2946
|
-
const sessionInfo = {
|
|
2947
|
-
authInfo: __privateGet(this, _authInfo),
|
|
2948
|
-
userId: this.userId,
|
|
2949
|
-
wallets: this.wallets,
|
|
2950
|
-
currentWalletIds: this.currentWalletIds,
|
|
2951
|
-
sessionCookie: this.retrieveSessionCookie(),
|
|
2952
|
-
externalWallets: this.externalWallets
|
|
2953
|
-
};
|
|
2954
|
-
return Buffer.from(JSON.stringify(sessionInfo)).toString("base64");
|
|
2955
|
-
}
|
|
2956
|
-
/**
|
|
2957
|
-
* Imports a session serialized by another Para instance.
|
|
2958
|
-
* @param {string} serializedInstanceBase64 the serialized session
|
|
2959
|
-
*/
|
|
2960
|
-
importSession(serializedInstanceBase64) {
|
|
2961
|
-
return __async(this, null, function* () {
|
|
2962
|
-
var _a, _b;
|
|
2963
|
-
const serializedInstance = Buffer.from(serializedInstanceBase64, "base64").toString("utf8");
|
|
2964
|
-
const sessionInfo = jsonParse(serializedInstance);
|
|
2965
|
-
const authInfo = (_a = sessionInfo.authInfo) != null ? _a : __privateMethod(this, _ParaCore_instances, toAuthInfo_fn).call(this, sessionInfo);
|
|
2966
|
-
yield __privateMethod(this, _ParaCore_instances, setAuthInfo_fn).call(this, authInfo);
|
|
2967
|
-
yield this.setUserId(sessionInfo.userId);
|
|
2968
|
-
yield this.setWallets(sessionInfo.wallets);
|
|
2969
|
-
yield this.setExternalWallets(sessionInfo.externalWallets || {});
|
|
2970
|
-
for (const walletId of Object.keys(this.wallets)) {
|
|
2971
|
-
if (!this.wallets[walletId].userId) {
|
|
2972
|
-
this.wallets[walletId].userId = this.userId;
|
|
2973
|
-
}
|
|
2974
|
-
}
|
|
2975
|
-
if (Object.keys(sessionInfo.currentWalletIds).length !== 0) {
|
|
2976
|
-
yield this.setCurrentWalletIds(sessionInfo.currentWalletIds);
|
|
2977
|
-
} else {
|
|
2978
|
-
const currentWalletIds = {};
|
|
2979
|
-
for (const walletId of Object.keys(sessionInfo.wallets)) {
|
|
2980
|
-
currentWalletIds[sessionInfo.wallets[walletId].type] = [
|
|
2981
|
-
...(_b = currentWalletIds[sessionInfo.wallets[walletId].type]) != null ? _b : [],
|
|
2982
|
-
walletId
|
|
2983
|
-
];
|
|
2984
|
-
}
|
|
2985
|
-
yield this.setCurrentWalletIds(currentWalletIds);
|
|
2986
|
-
}
|
|
2987
|
-
this.persistSessionCookie(sessionInfo.sessionCookie);
|
|
2988
|
-
});
|
|
2989
|
-
}
|
|
2990
|
-
/**
|
|
2991
|
-
* @deprecated
|
|
2992
|
-
*/
|
|
2993
|
-
// protected exitAccountCreation() {
|
|
2994
|
-
// this.isAwaitingAccountCreation = false;
|
|
2995
|
-
// }
|
|
2996
|
-
/**
|
|
2997
|
-
* @deprecated
|
|
2998
|
-
*/
|
|
2999
|
-
// protected exitLogin() {
|
|
3000
|
-
// this.isAwaitingLogin = false;
|
|
3001
|
-
// }
|
|
3002
|
-
/**
|
|
3003
|
-
* @deprecated
|
|
3004
|
-
*/
|
|
3005
|
-
// protected exitFarcaster() {
|
|
3006
|
-
// this.isAwaitingFarcaster = false;
|
|
3007
|
-
// }
|
|
3008
|
-
/**
|
|
3009
|
-
* @deprecated
|
|
3010
|
-
*/
|
|
3011
|
-
// protected exitOAuth() {
|
|
3012
|
-
// this.isAwaitingOAuth = false;
|
|
3013
|
-
// }
|
|
3014
|
-
/**
|
|
3015
|
-
* @deprecated
|
|
3016
|
-
*/
|
|
3017
|
-
// protected exitLoops() {
|
|
3018
|
-
// this.exitAccountCreation();
|
|
3019
|
-
// this.exitLogin();
|
|
3020
|
-
// this.exitFarcaster();
|
|
3021
|
-
// this.exitOAuth();
|
|
3022
|
-
// }
|
|
3023
|
-
/**
|
|
3024
|
-
* Retrieves a token to verify the current session.
|
|
3025
|
-
* @returns {Promise<string>} the ID
|
|
3026
|
-
**/
|
|
3027
|
-
getVerificationToken() {
|
|
3028
|
-
return __async(this, null, function* () {
|
|
3029
|
-
const { sessionLookupId } = yield this.touchSession();
|
|
3030
|
-
return sessionLookupId;
|
|
3031
|
-
});
|
|
3032
|
-
}
|
|
3033
|
-
/**
|
|
3034
|
-
* Logs the user out.
|
|
3035
|
-
* @param {Object} opts the options object.
|
|
3036
|
-
* @param {boolean} opts.clearPregenWallets if `true`, will remove all pregen wallets from storage
|
|
3037
|
-
**/
|
|
3038
|
-
logout() {
|
|
3039
|
-
return __async(this, arguments, function* ({ clearPregenWallets = false } = {}) {
|
|
3040
|
-
yield this.ctx.client.logout();
|
|
3041
|
-
yield this.clearStorage();
|
|
3042
|
-
if (!clearPregenWallets) {
|
|
3043
|
-
Object.entries(this.wallets).forEach(([id, wallet]) => {
|
|
3044
|
-
if (!wallet.pregenIdentifier) {
|
|
3045
|
-
delete this.wallets[id];
|
|
3046
|
-
}
|
|
3047
|
-
});
|
|
3048
|
-
yield this.setWallets(this.wallets);
|
|
3049
|
-
} else {
|
|
3050
|
-
this.wallets = {};
|
|
3051
|
-
}
|
|
3052
|
-
this.currentWalletIds = {};
|
|
3053
|
-
this.externalWallets = {};
|
|
3054
|
-
this.loginEncryptionKeyPair = void 0;
|
|
3055
|
-
__privateSet(this, _authInfo, void 0);
|
|
3056
|
-
this.userId = void 0;
|
|
3057
|
-
this.sessionCookie = void 0;
|
|
3058
|
-
dispatchEvent(ParaEvent.LOGOUT_EVENT, null);
|
|
3059
|
-
});
|
|
3060
|
-
}
|
|
3061
|
-
/** @deprecated */
|
|
3062
|
-
getSupportedCreateAuthMethods() {
|
|
3063
|
-
return __async(this, null, function* () {
|
|
3064
|
-
const partner = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
3065
|
-
let supportedAuthMethods = /* @__PURE__ */ new Set();
|
|
3066
|
-
for (const authMethod of partner.supportedAuthMethods) {
|
|
3067
|
-
supportedAuthMethods.add(AuthMethod[authMethod]);
|
|
3068
|
-
}
|
|
3069
|
-
return supportedAuthMethods;
|
|
3070
|
-
});
|
|
3071
|
-
}
|
|
3072
|
-
/**
|
|
3073
|
-
* Converts to a string, removing sensitive data when logging this class.
|
|
3074
|
-
*
|
|
3075
|
-
* Doesn't work for all types of logging.
|
|
3076
|
-
**/
|
|
3077
|
-
toString() {
|
|
3078
|
-
var _a, _b, _c;
|
|
3079
|
-
const redactedWallets = Object.keys(this.wallets).reduce(
|
|
3080
|
-
(acc, walletId) => __spreadProps(__spreadValues({}, acc), {
|
|
3081
|
-
[walletId]: __spreadProps(__spreadValues({}, this.wallets[walletId]), {
|
|
3082
|
-
signer: this.wallets[walletId].signer ? "[REDACTED]" : void 0
|
|
3083
|
-
})
|
|
3084
|
-
}),
|
|
3085
|
-
{}
|
|
3086
|
-
);
|
|
3087
|
-
const redactedExternalWallets = Object.keys(this.externalWallets).reduce(
|
|
3088
|
-
(acc, walletId) => __spreadProps(__spreadValues({}, acc), {
|
|
3089
|
-
[walletId]: __spreadProps(__spreadValues({}, this.externalWallets[walletId]), {
|
|
3090
|
-
signer: this.externalWallets[walletId].signer ? "[REDACTED]" : void 0
|
|
3091
|
-
})
|
|
3092
|
-
}),
|
|
3093
|
-
{}
|
|
3094
|
-
);
|
|
3095
|
-
const obj = {
|
|
3096
|
-
partnerId: (_a = __privateGet(this, _partner)) == null ? void 0 : _a.id,
|
|
3097
|
-
supportedWalletTypes: (_b = __privateGet(this, _partner)) == null ? void 0 : _b.supportedWalletTypes,
|
|
3098
|
-
cosmosPrefix: (_c = __privateGet(this, _partner)) == null ? void 0 : _c.cosmosPrefix,
|
|
3099
|
-
authInfo: __privateGet(this, _authInfo),
|
|
3100
|
-
userId: this.userId,
|
|
3101
|
-
pregenIds: this.pregenIds,
|
|
3102
|
-
currentWalletIds: this.currentWalletIds,
|
|
3103
|
-
wallets: redactedWallets,
|
|
3104
|
-
externalWallets: redactedExternalWallets,
|
|
3105
|
-
loginEncryptionKeyPair: this.loginEncryptionKeyPair ? "[REDACTED]" : void 0,
|
|
3106
|
-
ctx: {
|
|
3107
|
-
apiKey: this.ctx.apiKey,
|
|
3108
|
-
disableWorkers: this.ctx.disableWorkers,
|
|
3109
|
-
disableWebSockets: this.ctx.disableWebSockets,
|
|
3110
|
-
env: this.ctx.env,
|
|
3111
|
-
offloadMPCComputationURL: this.ctx.offloadMPCComputationURL,
|
|
3112
|
-
useLocalFiles: this.ctx.useLocalFiles,
|
|
3113
|
-
useDKLS: this.ctx.useDKLS,
|
|
3114
|
-
cosmosPrefix: this.ctx.cosmosPrefix
|
|
3115
|
-
}
|
|
3116
|
-
};
|
|
3117
|
-
return `Para ${JSON.stringify(obj, null, 2)}`;
|
|
3118
|
-
}
|
|
3119
|
-
/** NEW METHODS */
|
|
3120
|
-
getNewCredentialAndUrl() {
|
|
3121
|
-
return __async(this, arguments, function* ({
|
|
3122
|
-
authMethod = "PASSKEY",
|
|
3123
|
-
isForNewDevice = false,
|
|
3124
|
-
portalTheme,
|
|
3125
|
-
shorten = false
|
|
3126
|
-
} = {}) {
|
|
3127
|
-
this.assertIsAuthSet();
|
|
3128
|
-
let credentialId, urlType;
|
|
3129
|
-
switch (authMethod) {
|
|
3130
|
-
case "PASSKEY":
|
|
3131
|
-
({
|
|
3132
|
-
data: { id: credentialId }
|
|
3133
|
-
} = yield this.ctx.client.addSessionPublicKey(this.userId, {
|
|
3134
|
-
status: PublicKeyStatus.PENDING,
|
|
3135
|
-
type: PublicKeyType.WEB
|
|
3136
|
-
}));
|
|
3137
|
-
urlType = "createAuth";
|
|
3138
|
-
break;
|
|
3139
|
-
case "PASSWORD":
|
|
3140
|
-
({
|
|
3141
|
-
data: { id: credentialId }
|
|
3142
|
-
} = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
|
|
3143
|
-
status: PasswordStatus.PENDING
|
|
3144
|
-
}));
|
|
3145
|
-
urlType = "createPassword";
|
|
3146
|
-
break;
|
|
3147
|
-
}
|
|
3148
|
-
const url = yield this.constructPortalUrl(urlType, {
|
|
3149
|
-
isForNewDevice,
|
|
3150
|
-
pathId: credentialId,
|
|
3151
|
-
portalTheme,
|
|
3152
|
-
shorten
|
|
3153
|
-
});
|
|
3154
|
-
return { credentialId, url };
|
|
3155
|
-
});
|
|
3156
|
-
}
|
|
3157
|
-
/**
|
|
3158
|
-
* Returns a Para Portal URL for logging in with a WebAuth passkey or a password.
|
|
3159
|
-
* @param {Object} opts the options object
|
|
3160
|
-
* @param {String} opts.auth - the user auth to sign up or log in with, in the form ` { email: string } | { phone: `+${number}` } `
|
|
3161
|
-
* @param {boolean} opts.useShortUrls - whether to shorten the generated portal URLs
|
|
3162
|
-
* @param {Theme} opts.portalTheme the Para Portal theme to apply to the password creation URL, if other than the default theme
|
|
3163
|
-
* @returns {SignUpOrLogInResponse} an object in the form of either: `{ stage: 'verify' }` or `{ stage: 'login'; passkeyUrl?: string; passwordUrl?: string; biometricHints?: BiometricLocationHint[] }`
|
|
3164
|
-
*/
|
|
3165
|
-
getLoginUrl(_0) {
|
|
3166
|
-
return __async(this, arguments, function* ({
|
|
3167
|
-
authMethod = "PASSKEY",
|
|
3168
|
-
shorten = false,
|
|
3169
|
-
portalTheme,
|
|
3170
|
-
sessionId
|
|
3171
|
-
}) {
|
|
3172
|
-
if (!sessionId) {
|
|
3173
|
-
sessionId = (yield this.touchSession()).sessionLookupId;
|
|
3174
|
-
}
|
|
3175
|
-
this.assertIsAuthSet();
|
|
3176
|
-
let urlType;
|
|
3177
|
-
switch (authMethod) {
|
|
3178
|
-
case "PASSKEY":
|
|
3179
|
-
urlType = "loginAuth";
|
|
3180
|
-
break;
|
|
3181
|
-
case "PASSWORD":
|
|
3182
|
-
urlType = "loginPassword";
|
|
3183
|
-
break;
|
|
3184
|
-
default:
|
|
3185
|
-
throw new Error(`invalid authentication method: '${authMethod}'`);
|
|
3186
|
-
}
|
|
3187
|
-
return this.constructPortalUrl(urlType, {
|
|
3188
|
-
sessionId,
|
|
3189
|
-
shorten,
|
|
3190
|
-
portalTheme
|
|
3191
|
-
});
|
|
3192
|
-
});
|
|
3193
|
-
}
|
|
3194
|
-
getOAuthUrl(_0) {
|
|
3195
|
-
return __async(this, arguments, function* ({ method, deeplinkUrl }) {
|
|
3196
|
-
yield this.logout();
|
|
3197
|
-
const { sessionLookupId } = yield this.touchSession(true);
|
|
3198
|
-
return constructUrl({
|
|
3199
|
-
base: getBaseOAuthUrl(this.ctx.env),
|
|
3200
|
-
path: `/auth/${method}`,
|
|
3201
|
-
params: {
|
|
3202
|
-
apiKey: this.ctx.apiKey,
|
|
3203
|
-
sessionLookupId,
|
|
3204
|
-
deeplinkUrl
|
|
3205
|
-
}
|
|
3206
|
-
});
|
|
3207
|
-
});
|
|
3208
|
-
}
|
|
3209
|
-
signUpOrLogIn(_c) {
|
|
3210
|
-
return __async(this, null, function* () {
|
|
3211
|
-
var _d = _c, { auth } = _d, urlOptions = __objRest(_d, ["auth"]);
|
|
3212
|
-
const serverAuthState = yield this.ctx.client.signUpOrLogIn(__spreadValues(__spreadValues({}, auth), this.getVerificationEmailProps()));
|
|
3213
|
-
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
3214
|
-
});
|
|
3215
|
-
}
|
|
3216
|
-
verifyNewAccount(_e) {
|
|
3217
|
-
return __async(this, null, function* () {
|
|
3218
|
-
var _f = _e, {
|
|
3219
|
-
verificationCode
|
|
3220
|
-
} = _f, urlOptions = __objRest(_f, [
|
|
3221
|
-
"verificationCode"
|
|
3222
|
-
]);
|
|
3223
|
-
this.assertIsAuthSet(["email", "phone"]);
|
|
3224
|
-
const userId = this.assertUserId();
|
|
3225
|
-
const serverAuthState = yield this.ctx.client.verifyNewAccount(userId, {
|
|
3226
|
-
verificationCode
|
|
3227
|
-
});
|
|
3228
|
-
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
3229
|
-
});
|
|
3230
|
-
}
|
|
3231
|
-
verifyOAuth(_g) {
|
|
3232
|
-
return __async(this, null, function* () {
|
|
3233
|
-
var _h = _g, {
|
|
3234
|
-
method,
|
|
3235
|
-
deeplinkUrl,
|
|
3236
|
-
isCanceled = () => false,
|
|
3237
|
-
onCancel,
|
|
3238
|
-
onPoll,
|
|
3239
|
-
onOAuthUrl
|
|
3240
|
-
} = _h, urlOptions = __objRest(_h, [
|
|
3241
|
-
"method",
|
|
3242
|
-
"deeplinkUrl",
|
|
3243
|
-
"isCanceled",
|
|
3244
|
-
"onCancel",
|
|
3245
|
-
"onPoll",
|
|
3246
|
-
"onOAuthUrl"
|
|
3247
|
-
]);
|
|
3248
|
-
const sessionLookupId = yield __privateMethod(this, _ParaCore_instances, prepareLogin_fn).call(this);
|
|
3249
|
-
const oAuthUrl = constructUrl({
|
|
3250
|
-
base: getBaseOAuthUrl(this.ctx.env),
|
|
3251
|
-
path: `/auth/${method}`,
|
|
3252
|
-
params: {
|
|
3253
|
-
apiKey: this.ctx.apiKey,
|
|
3254
|
-
sessionLookupId,
|
|
3255
|
-
deeplinkUrl
|
|
3256
|
-
}
|
|
3257
|
-
});
|
|
3258
|
-
onOAuthUrl(oAuthUrl);
|
|
3259
|
-
const startedAt = Date.now();
|
|
3260
|
-
return new Promise((resolve, reject) => {
|
|
3261
|
-
(() => __async(this, null, function* () {
|
|
3262
|
-
while (true) {
|
|
3263
|
-
try {
|
|
3264
|
-
if (isCanceled() || Date.now() - startedAt > POLLING_TIMEOUT_MS) {
|
|
3265
|
-
onCancel == null ? void 0 : onCancel();
|
|
3266
|
-
return reject("canceled");
|
|
3267
|
-
}
|
|
3268
|
-
yield new Promise((_resolve) => setTimeout(_resolve, POLLING_INTERVAL_MS));
|
|
3269
|
-
const serverAuthState = yield this.ctx.client.verifyOAuth();
|
|
3270
|
-
if (isServerAuthState(serverAuthState)) {
|
|
3271
|
-
const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
|
|
3272
|
-
return resolve(authState);
|
|
3273
|
-
}
|
|
3274
|
-
onPoll == null ? void 0 : onPoll();
|
|
3275
|
-
} catch (err) {
|
|
3276
|
-
console.error(err);
|
|
3277
|
-
onPoll == null ? void 0 : onPoll();
|
|
3278
|
-
}
|
|
3279
|
-
}
|
|
3280
|
-
}))();
|
|
3281
|
-
});
|
|
3282
|
-
});
|
|
3283
|
-
}
|
|
3284
|
-
verifyFarcaster(_i) {
|
|
3285
|
-
return __async(this, null, function* () {
|
|
3286
|
-
var _j = _i, {
|
|
3287
|
-
isCanceled = () => false,
|
|
3288
|
-
onConnectUri,
|
|
3289
|
-
onCancel,
|
|
3290
|
-
onPoll
|
|
3291
|
-
} = _j, urlOptions = __objRest(_j, [
|
|
3292
|
-
"isCanceled",
|
|
3293
|
-
"onConnectUri",
|
|
3294
|
-
"onCancel",
|
|
3295
|
-
"onPoll"
|
|
3296
|
-
]);
|
|
3297
|
-
const {
|
|
3298
|
-
data: { connect_uri: connectUri }
|
|
3299
|
-
} = yield this.ctx.client.initializeFarcasterLogin();
|
|
3300
|
-
onConnectUri(connectUri);
|
|
3301
|
-
return new Promise((resolve, reject) => {
|
|
3302
|
-
(() => __async(this, null, function* () {
|
|
3303
|
-
const startedAt = Date.now();
|
|
3304
|
-
while (true) {
|
|
3305
|
-
try {
|
|
3306
|
-
if (isCanceled() || Date.now() - startedAt > POLLING_TIMEOUT_MS) {
|
|
3307
|
-
onCancel == null ? void 0 : onCancel();
|
|
3308
|
-
return reject("canceled");
|
|
3309
|
-
}
|
|
3310
|
-
yield new Promise((_resolve) => setTimeout(_resolve, POLLING_INTERVAL_MS));
|
|
3311
|
-
const serverAuthState = yield this.ctx.client.getFarcasterAuthStatus();
|
|
3312
|
-
if (isServerAuthState(serverAuthState)) {
|
|
3313
|
-
const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
3314
|
-
return resolve(authState);
|
|
3315
|
-
}
|
|
3316
|
-
onPoll == null ? void 0 : onPoll();
|
|
3317
|
-
} catch (e) {
|
|
3318
|
-
console.error(e);
|
|
3319
|
-
return reject(e);
|
|
3320
|
-
}
|
|
3321
|
-
}
|
|
3322
|
-
}))();
|
|
3323
|
-
});
|
|
3324
|
-
});
|
|
3325
|
-
}
|
|
3326
|
-
/**
|
|
3327
|
-
* Validates the response received from an attempted Telegram login for authenticity, then
|
|
3328
|
-
* creates or retrieves the corresponding Para user and prepares the Para instance to sign in with that user.
|
|
3329
|
-
* @param authResponse - the response JSON object received from the Telegram widget.
|
|
3330
|
-
* @returns `{ isValid: boolean; telegramUserId?: string; userId?: string; isNewUser?: boolean; supportedAuthMethods?: AuthMethod[]; biometricHints?: BiometricLocationHint[] }`
|
|
3331
|
-
*/
|
|
3332
|
-
verifyTelegram(_k) {
|
|
3333
|
-
return __async(this, null, function* () {
|
|
3334
|
-
var _l = _k, {
|
|
3335
|
-
telegramAuthResponse
|
|
3336
|
-
} = _l, urlOptions = __objRest(_l, [
|
|
3337
|
-
"telegramAuthResponse"
|
|
3338
|
-
]);
|
|
3339
|
-
try {
|
|
3340
|
-
const serverAuthState = yield this.ctx.client.verifyTelegram(telegramAuthResponse);
|
|
3341
|
-
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
3342
|
-
} catch (e) {
|
|
3343
|
-
throw new Error(e.message);
|
|
3344
|
-
}
|
|
3345
|
-
});
|
|
3346
|
-
}
|
|
3347
|
-
/**
|
|
3348
|
-
* Waits for the session to be active and sets up the user.
|
|
3349
|
-
*
|
|
3350
|
-
* @param {Object} opts the options object
|
|
3351
|
-
* @param {Window} [opts.popupWindow] the popup window being used for login.
|
|
3352
|
-
* @param {boolean} [opts.skipSessionRefresh] whether to skip refreshing the session.
|
|
3353
|
-
* @returns {Object} `{ isComplete: boolean; isError: boolean; needsWallet: boolean; partnerId: string; }` the result data
|
|
3354
|
-
**/
|
|
3355
|
-
waitForLogin() {
|
|
3356
|
-
return __async(this, arguments, function* ({
|
|
3357
|
-
isCanceled = () => false,
|
|
3358
|
-
onCancel,
|
|
3359
|
-
onPoll,
|
|
3360
|
-
skipSessionRefresh = false
|
|
3361
|
-
} = {}) {
|
|
3362
|
-
const startedAt = Date.now();
|
|
3363
|
-
return new Promise((resolve, reject) => {
|
|
3364
|
-
(() => __async(this, null, function* () {
|
|
3365
|
-
var _a;
|
|
3366
|
-
if (!this.isExternalWalletAuth) {
|
|
3367
|
-
this.externalWallets = {};
|
|
3368
|
-
}
|
|
3369
|
-
while (true) {
|
|
3370
|
-
if (isCanceled() || Date.now() - startedAt > POLLING_TIMEOUT_MS) {
|
|
3371
|
-
dispatchEvent(ParaEvent.LOGIN_EVENT, { isComplete: false }, "failed to setup user");
|
|
3372
|
-
onCancel == null ? void 0 : onCancel();
|
|
3373
|
-
return reject("canceled");
|
|
3374
|
-
}
|
|
3375
|
-
yield new Promise((resolve2) => setTimeout(resolve2, POLLING_INTERVAL_MS));
|
|
3376
|
-
try {
|
|
3377
|
-
let session = yield this.touchSession();
|
|
3378
|
-
if (!session.isAuthenticated) {
|
|
3379
|
-
onPoll == null ? void 0 : onPoll();
|
|
3380
|
-
continue;
|
|
3381
|
-
}
|
|
3382
|
-
session = yield this.userSetupAfterLogin();
|
|
3383
|
-
const needsWallet = (_a = session.needsWallet) != null ? _a : false;
|
|
3384
|
-
if (!needsWallet) {
|
|
3385
|
-
if (this.currentWalletIdsArray.length === 0) {
|
|
3386
|
-
onPoll == null ? void 0 : onPoll();
|
|
3387
|
-
continue;
|
|
3388
|
-
}
|
|
3389
|
-
}
|
|
3390
|
-
const fetchedWallets = yield this.fetchWallets();
|
|
3391
|
-
const tempSharesRes = yield this.getTransmissionKeyShares();
|
|
3392
|
-
if (tempSharesRes.data.temporaryShares.length === fetchedWallets.length) {
|
|
3393
|
-
yield this.setupAfterLogin({ temporaryShares: tempSharesRes.data.temporaryShares, skipSessionRefresh });
|
|
3394
|
-
yield this.claimPregenWallets();
|
|
3395
|
-
const resp = {
|
|
3396
|
-
needsWallet: needsWallet || Object.values(this.wallets).length === 0,
|
|
3397
|
-
partnerId: session.partnerId
|
|
3398
|
-
};
|
|
3399
|
-
dispatchEvent(ParaEvent.LOGIN_EVENT, resp);
|
|
3400
|
-
return resolve(resp);
|
|
3401
|
-
}
|
|
3402
|
-
onPoll == null ? void 0 : onPoll();
|
|
3403
|
-
} catch (err) {
|
|
3404
|
-
console.error(err);
|
|
3405
|
-
onPoll == null ? void 0 : onPoll();
|
|
3406
|
-
}
|
|
3407
|
-
}
|
|
3408
|
-
}))();
|
|
3409
|
-
});
|
|
3410
|
-
});
|
|
3411
|
-
}
|
|
3412
|
-
waitForSignup(_0) {
|
|
3413
|
-
return __async(this, arguments, function* ({
|
|
3414
|
-
isCanceled = () => false,
|
|
3415
|
-
onCancel,
|
|
3416
|
-
onPoll
|
|
3417
|
-
}) {
|
|
3418
|
-
const startedAt = Date.now();
|
|
3419
|
-
return new Promise((resolve, reject) => {
|
|
3420
|
-
(() => __async(this, null, function* () {
|
|
3421
|
-
yield this.touchSession();
|
|
3422
|
-
if (!this.isExternalWalletAuth) {
|
|
3423
|
-
this.externalWallets = {};
|
|
3424
|
-
}
|
|
3425
|
-
while (true) {
|
|
3426
|
-
try {
|
|
3427
|
-
if (isCanceled() || Date.now() - startedAt > POLLING_TIMEOUT_MS) {
|
|
3428
|
-
onCancel == null ? void 0 : onCancel();
|
|
3429
|
-
dispatchEvent(ParaEvent.ACCOUNT_CREATION_EVENT, false, "failed to sign up user");
|
|
3430
|
-
return reject("canceled");
|
|
3431
|
-
}
|
|
3432
|
-
yield new Promise((_resolve) => setTimeout(_resolve, POLLING_INTERVAL_MS));
|
|
3433
|
-
if (yield this.isSessionActive()) {
|
|
3434
|
-
dispatchEvent(ParaEvent.ACCOUNT_CREATION_EVENT, true);
|
|
3435
|
-
return resolve(true);
|
|
3436
|
-
}
|
|
3437
|
-
onPoll == null ? void 0 : onPoll();
|
|
3438
|
-
} catch (err) {
|
|
3439
|
-
console.error(err);
|
|
3440
|
-
onPoll == null ? void 0 : onPoll();
|
|
3441
|
-
}
|
|
3442
|
-
}
|
|
3443
|
-
}))();
|
|
3444
|
-
});
|
|
3445
|
-
});
|
|
3446
|
-
}
|
|
3447
|
-
waitForWalletCreation() {
|
|
3448
|
-
return __async(this, arguments, function* ({
|
|
3449
|
-
isCanceled = () => false,
|
|
3450
|
-
onCancel
|
|
3451
|
-
} = {}) {
|
|
3452
|
-
yield this.waitForSignup({ isCanceled, onCancel });
|
|
3453
|
-
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
3454
|
-
const pregenWallets = yield this.getPregenWallets();
|
|
3455
|
-
let recoverySecret, walletIds = {};
|
|
3456
|
-
if (pregenWallets.length > 0) {
|
|
3457
|
-
recoverySecret = yield this.claimPregenWallets();
|
|
3458
|
-
walletIds = supportedWalletTypes.reduce((acc, { type }) => {
|
|
3459
|
-
var _a;
|
|
3460
|
-
return __spreadProps(__spreadValues({}, acc), {
|
|
3461
|
-
[type]: [(_a = pregenWallets.find((w) => !!WalletSchemeTypeMap[w.scheme][type])) == null ? void 0 : _a.id]
|
|
3462
|
-
});
|
|
3463
|
-
}, {});
|
|
3464
|
-
}
|
|
3465
|
-
const created = yield this.createWalletPerType();
|
|
3466
|
-
recoverySecret = recoverySecret != null ? recoverySecret : created.recoverySecret;
|
|
3467
|
-
walletIds = __spreadValues(__spreadValues({}, walletIds), created.walletIds);
|
|
3468
|
-
const resp = { walletIds, recoverySecret };
|
|
3469
|
-
dispatchEvent(ParaEvent.ACCOUNT_SETUP_EVENT, resp);
|
|
3470
|
-
return resp;
|
|
3471
|
-
});
|
|
3472
|
-
}
|
|
3473
|
-
loginExternalWallet(_m) {
|
|
3474
|
-
return __async(this, null, function* () {
|
|
3475
|
-
var _n = _m, {
|
|
3476
|
-
externalWallet
|
|
3477
|
-
} = _n, urlOptions = __objRest(_n, [
|
|
3478
|
-
"externalWallet"
|
|
3479
|
-
]);
|
|
3480
|
-
this.requireApiKey();
|
|
3481
|
-
const serverAuthState = yield this.ctx.client.loginExternalWallet({ externalWallet });
|
|
3482
|
-
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
3483
|
-
});
|
|
3484
|
-
}
|
|
3485
|
-
verifyExternalWallet(_o) {
|
|
3486
|
-
return __async(this, null, function* () {
|
|
3487
|
-
var _p = _o, {
|
|
3488
|
-
externalWallet,
|
|
3489
|
-
signedMessage,
|
|
3490
|
-
cosmosPublicKeyHex,
|
|
3491
|
-
cosmosSigner
|
|
3492
|
-
} = _p, urlOptions = __objRest(_p, [
|
|
3493
|
-
"externalWallet",
|
|
3494
|
-
"signedMessage",
|
|
3495
|
-
"cosmosPublicKeyHex",
|
|
3496
|
-
"cosmosSigner"
|
|
3497
|
-
]);
|
|
3498
|
-
const serverAuthState = yield this.ctx.client.verifyExternalWallet(this.userId, {
|
|
3499
|
-
externalWallet,
|
|
3500
|
-
signedMessage,
|
|
3501
|
-
cosmosPublicKeyHex,
|
|
3502
|
-
cosmosSigner
|
|
3503
|
-
});
|
|
3504
|
-
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
3505
|
-
});
|
|
3506
|
-
}
|
|
3507
|
-
/**
|
|
3508
|
-
* Performs 2FA verification.
|
|
3509
|
-
* @param {Object} opts the options object
|
|
3510
|
-
* @param {string} opts.email the email to use for performing a 2FA verification.
|
|
3511
|
-
* @param {string} opts.verificationCode the verification code to received via 2FA.
|
|
3512
|
-
* @returns {Object} `{ address, initiatedAt, status, userId, walletId }`
|
|
3513
|
-
*/
|
|
3514
|
-
verify2fa(_0) {
|
|
3515
|
-
return __async(this, arguments, function* ({ auth, verificationCode }) {
|
|
3516
|
-
const res = yield this.ctx.client.verify2FA(auth, verificationCode);
|
|
3517
|
-
return {
|
|
3518
|
-
initiatedAt: res.data.initiatedAt,
|
|
3519
|
-
status: res.data.status,
|
|
3520
|
-
userId: res.data.userId,
|
|
3521
|
-
wallets: res.data.wallets
|
|
3522
|
-
};
|
|
3523
|
-
});
|
|
3524
|
-
}
|
|
3525
|
-
/**
|
|
3526
|
-
* Sets up two-factor authentication for the current user.
|
|
3527
|
-
* @returns {string} uri - uri to use for setting up 2FA
|
|
3528
|
-
* */
|
|
3529
|
-
setup2fa() {
|
|
3530
|
-
return __async(this, null, function* () {
|
|
3531
|
-
const userId = this.assertUserId();
|
|
3532
|
-
const res = yield this.ctx.client.setup2FA(userId);
|
|
3533
|
-
return res;
|
|
3534
|
-
});
|
|
3535
|
-
}
|
|
3536
|
-
/**
|
|
3537
|
-
* Enables 2FA.
|
|
3538
|
-
* @param {Object} opts the options object
|
|
3539
|
-
* @param {string} opts.verificationCode - the verification code received via 2FA.
|
|
3540
|
-
*/
|
|
3541
|
-
enable2fa(_0) {
|
|
3542
|
-
return __async(this, arguments, function* ({ verificationCode }) {
|
|
3543
|
-
const userId = this.assertUserId();
|
|
3544
|
-
yield this.ctx.client.enable2FA(userId, verificationCode);
|
|
3545
|
-
});
|
|
3546
|
-
}
|
|
3547
|
-
/**
|
|
3548
|
-
* Creates a new pregenerated wallet.
|
|
3549
|
-
*
|
|
3550
|
-
* @param {Object} opts the options object.
|
|
3551
|
-
* @param {string} opts.pregenIdentifier the identifier associated with the new wallet.
|
|
3552
|
-
* @param {TPregenIdentifierType} [opts.pregenIdentifierType] the identifier type. Defaults to `EMAIL`.
|
|
3553
|
-
* @param {WalletType} [opts.type] the type of wallet to create. Defaults to the first non-optional type in the instance's `supportedWalletTypes` array.
|
|
3554
|
-
* @returns {Wallet} the created wallet.
|
|
3555
|
-
**/
|
|
3556
|
-
createPregenWallet(opts) {
|
|
3557
|
-
return __async(this, null, function* () {
|
|
3558
|
-
var _a, _b;
|
|
3559
|
-
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
3560
|
-
const { type: _type = (_a = supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type, pregenId } = opts;
|
|
3561
|
-
this.requireApiKey();
|
|
3562
|
-
const walletType = yield this.assertIsValidWalletType(
|
|
3563
|
-
_type != null ? _type : (_b = supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _b.type
|
|
3564
|
-
);
|
|
3565
|
-
const [pregenIdentifierType, pregenIdentifier] = toPregenTypeAndId(pregenId);
|
|
3566
|
-
let keygenRes;
|
|
3567
|
-
switch (walletType) {
|
|
3568
|
-
case WalletType2.SOLANA:
|
|
3569
|
-
keygenRes = yield this.platformUtils.ed25519PreKeygen(
|
|
3570
|
-
this.ctx,
|
|
3571
|
-
pregenIdentifier,
|
|
3572
|
-
pregenIdentifierType,
|
|
3573
|
-
this.retrieveSessionCookie()
|
|
3574
|
-
);
|
|
3575
|
-
break;
|
|
3576
|
-
default:
|
|
3577
|
-
keygenRes = yield this.platformUtils.preKeygen(
|
|
3578
|
-
this.ctx,
|
|
3579
|
-
void 0,
|
|
3580
|
-
pregenIdentifier,
|
|
3581
|
-
pregenIdentifierType,
|
|
3582
|
-
walletType,
|
|
3583
|
-
null,
|
|
3584
|
-
this.retrieveSessionCookie()
|
|
3585
|
-
);
|
|
3586
|
-
break;
|
|
3587
|
-
}
|
|
3588
|
-
const { signer, walletId } = keygenRes;
|
|
3589
|
-
this.wallets[walletId] = {
|
|
3590
|
-
id: walletId,
|
|
3591
|
-
signer,
|
|
3592
|
-
scheme: walletType === WalletType2.SOLANA ? WalletScheme2.ED25519 : WalletScheme2.DKLS,
|
|
3593
|
-
type: walletType,
|
|
3594
|
-
isPregen: true,
|
|
3595
|
-
pregenIdentifier,
|
|
3596
|
-
pregenIdentifierType
|
|
3597
|
-
};
|
|
3598
|
-
yield this.waitForPregenWalletAddress(walletId);
|
|
3599
|
-
yield this.populatePregenWalletAddresses();
|
|
3600
|
-
return this.wallets[walletId];
|
|
3601
|
-
});
|
|
3602
|
-
}
|
|
3603
|
-
/**
|
|
3604
|
-
* Creates new pregenerated wallets for each desired type.
|
|
3605
|
-
* If no types are provided, this method will create one for each of the non-optional types
|
|
3606
|
-
* specified in the instance's `supportedWalletTypes` array that are not already present.
|
|
3607
|
-
* @param {Object} opts the options object.
|
|
3608
|
-
* @param {string} opts.pregenIdentifier the identifier to associate each wallet with.
|
|
3609
|
-
* @param {TPregenIdentifierType} opts.pregenIdentifierType - either `'EMAIL'` or `'PHONE'`.
|
|
3610
|
-
* @param {WalletType[]} [opts.types] the wallet types to create. Defaults to any types the instance supports that are not already present.
|
|
3611
|
-
* @returns {Wallet[]} an array containing the created wallets.
|
|
3612
|
-
**/
|
|
3613
|
-
createPregenWalletPerType(_0) {
|
|
3614
|
-
return __async(this, arguments, function* ({
|
|
3615
|
-
types,
|
|
3616
|
-
pregenId
|
|
3617
|
-
}) {
|
|
3618
|
-
const wallets = [];
|
|
3619
|
-
for (const type of yield this.getTypesToCreate(types)) {
|
|
3620
|
-
const wallet = yield this.createPregenWallet({ type, pregenId });
|
|
3621
|
-
wallets.push(wallet);
|
|
3622
|
-
}
|
|
3623
|
-
return wallets;
|
|
3624
|
-
});
|
|
3625
|
-
}
|
|
3626
|
-
/**
|
|
3627
|
-
* Claims a pregenerated wallet.
|
|
3628
|
-
* @param {Object} opts the options object.
|
|
3629
|
-
* @param {string} opts.pregenIdentifier string the identifier of the user claiming the wallet
|
|
3630
|
-
* @param {TPregenIdentifierType} opts.pregenIdentifierType type of the identifier of the user claiming the wallet
|
|
3631
|
-
* @returns {[Wallet, string | null]} `[wallet, recoveryShare]` - the wallet object and the new recovery share.
|
|
3632
|
-
**/
|
|
3633
|
-
claimPregenWallets() {
|
|
3634
|
-
return __async(this, arguments, function* ({
|
|
3635
|
-
pregenId
|
|
3636
|
-
} = {}) {
|
|
3637
|
-
var _a;
|
|
3638
|
-
this.requireApiKey();
|
|
3639
|
-
const pregenWallets = pregenId ? yield this.getPregenWallets({ pregenId }) : yield this.getPregenWallets();
|
|
3640
|
-
if (pregenWallets.length === 0) {
|
|
3641
|
-
return void 0;
|
|
3642
|
-
}
|
|
3643
|
-
let newRecoverySecret;
|
|
3644
|
-
const { walletIds } = yield this.ctx.client.claimPregenWallets({
|
|
3645
|
-
userId: this.userId,
|
|
3646
|
-
walletIds: pregenWallets.map((w) => w.id)
|
|
3647
|
-
});
|
|
3648
|
-
for (const walletId of walletIds) {
|
|
3649
|
-
const wallet = this.wallets[walletId];
|
|
3650
|
-
let refreshedShare;
|
|
3651
|
-
if (wallet.scheme === WalletScheme2.ED25519) {
|
|
3652
|
-
const distributeRes = yield distributeNewShare({
|
|
3653
|
-
ctx: this.ctx,
|
|
3654
|
-
userId: this.userId,
|
|
3655
|
-
walletId: wallet.id,
|
|
3656
|
-
userShare: this.wallets[wallet.id].signer,
|
|
3657
|
-
emailProps: this.getBackupKitEmailProps(),
|
|
3658
|
-
partnerId: wallet.partnerId
|
|
3659
|
-
});
|
|
3660
|
-
if (distributeRes.length > 0) {
|
|
3661
|
-
newRecoverySecret = distributeRes;
|
|
3662
|
-
}
|
|
3663
|
-
} else {
|
|
3664
|
-
refreshedShare = yield this.refreshShare({
|
|
3665
|
-
walletId: wallet.id,
|
|
3666
|
-
share: this.wallets[wallet.id].signer,
|
|
3667
|
-
oldPartnerId: wallet.partnerId,
|
|
3668
|
-
newPartnerId: wallet.partnerId,
|
|
3669
|
-
redistributeBackupEncryptedShares: true
|
|
3670
|
-
});
|
|
3671
|
-
if (refreshedShare.recoverySecret) {
|
|
3672
|
-
newRecoverySecret = refreshedShare.recoverySecret;
|
|
3673
|
-
}
|
|
3674
|
-
}
|
|
3675
|
-
this.wallets[wallet.id] = __spreadProps(__spreadValues({}, this.wallets[wallet.id]), {
|
|
3676
|
-
signer: (_a = refreshedShare == null ? void 0 : refreshedShare.signer) != null ? _a : wallet.signer,
|
|
3677
|
-
userId: this.userId,
|
|
3678
|
-
pregenIdentifier: void 0,
|
|
3679
|
-
pregenIdentifierType: void 0
|
|
3680
|
-
});
|
|
3681
|
-
const walletNoSigner = __spreadValues({}, this.wallets[wallet.id]);
|
|
3682
|
-
delete walletNoSigner.signer;
|
|
3683
|
-
dispatchEvent(ParaEvent.PREGEN_WALLET_CLAIMED, {
|
|
3684
|
-
wallet: walletNoSigner,
|
|
3685
|
-
recoverySecret: newRecoverySecret
|
|
3686
|
-
});
|
|
3687
|
-
}
|
|
3688
|
-
yield this.setWallets(this.wallets);
|
|
3689
|
-
return newRecoverySecret;
|
|
3690
|
-
});
|
|
3691
|
-
}
|
|
3692
|
-
/**
|
|
3693
|
-
* Updates the identifier for a pregen wallet.
|
|
3694
|
-
* @param {Object} opts the options object.
|
|
3695
|
-
* @param {string} opts.walletId the pregen wallet ID
|
|
3696
|
-
* @param {string} opts.newPregenIdentifier the new identtifier
|
|
3697
|
-
* @param {TPregenIdentifierType} opts.newPregenIdentifierType: the new identifier type
|
|
3698
|
-
**/
|
|
3699
|
-
updatePregenWalletIdentifier(_0) {
|
|
3700
|
-
return __async(this, arguments, function* ({
|
|
3701
|
-
walletId,
|
|
3702
|
-
newPregenId
|
|
3703
|
-
}) {
|
|
3704
|
-
this.requireApiKey();
|
|
3705
|
-
const [newPregenIdentifierType, newPregenIdentifier] = toPregenTypeAndId(newPregenId);
|
|
3706
|
-
yield this.ctx.client.updatePregenWallet(walletId, {
|
|
3707
|
-
pregenIdentifier: newPregenIdentifier,
|
|
3708
|
-
pregenIdentifierType: newPregenIdentifierType
|
|
3709
|
-
});
|
|
3710
|
-
if (!!this.wallets[walletId]) {
|
|
3711
|
-
this.wallets[walletId] = __spreadProps(__spreadValues({}, this.wallets[walletId]), {
|
|
3712
|
-
pregenIdentifier: newPregenIdentifier,
|
|
3713
|
-
pregenIdentifierType: newPregenIdentifierType
|
|
3714
|
-
});
|
|
3715
|
-
yield this.setWallets(this.wallets);
|
|
3716
|
-
}
|
|
3717
|
-
});
|
|
3718
|
-
}
|
|
3719
|
-
/**
|
|
3720
|
-
* Checks if a pregen Wallet exists for the given identifier with the current partner.
|
|
3721
|
-
* @param {Object} opts the options object.
|
|
3722
|
-
* @param {string} opts.pregenIdentifier string the identifier of the user claiming the wallet
|
|
3723
|
-
* @param {TPregenIdentifierType} opts.pregenIdentifierType type of the string of the identifier of the user claiming the wallet
|
|
3724
|
-
* @returns {boolean} whether the pregen wallet exists
|
|
3725
|
-
**/
|
|
3726
|
-
hasPregenWallet(_0) {
|
|
3727
|
-
return __async(this, arguments, function* ({ pregenId }) {
|
|
3728
|
-
this.requireApiKey();
|
|
3729
|
-
const [pregenIdentifierType, pregenIdentifier] = toPregenTypeAndId(pregenId);
|
|
3730
|
-
const wallets = yield this.getPregenWallets({ pregenId });
|
|
3731
|
-
const wallet = wallets.find(
|
|
3732
|
-
(w) => w.pregenIdentifier === pregenIdentifier && w.pregenIdentifierType === pregenIdentifierType
|
|
3733
|
-
);
|
|
3734
|
-
if (!wallet) {
|
|
3735
|
-
return false;
|
|
3736
|
-
}
|
|
3737
|
-
return true;
|
|
3738
|
-
});
|
|
3739
|
-
}
|
|
3740
|
-
/**
|
|
3741
|
-
* Get pregen wallets for the given identifier.
|
|
3742
|
-
* @param {Object} opts the options object.
|
|
3743
|
-
* @param {string} opts.pregenIdentifier - the identifier of the user claiming the wallet
|
|
3744
|
-
* @param {TPregenIdentifierType} opts.pregenIdentifierType - type of the identifier of the user claiming the wallet
|
|
3745
|
-
* @returns {Promise<WalletEntity[]>} the array of found wallets
|
|
3746
|
-
**/
|
|
3747
|
-
getPregenWallets() {
|
|
3748
|
-
return __async(this, arguments, function* ({ pregenId } = {}) {
|
|
3749
|
-
this.requireApiKey();
|
|
3750
|
-
const res = yield this.ctx.client.getPregenWallets(
|
|
3751
|
-
pregenId ? toPregenIds(pregenId) : this.pregenIds,
|
|
3752
|
-
this.isPortal(),
|
|
3753
|
-
this.userId
|
|
3754
|
-
);
|
|
3755
|
-
return res.wallets.filter((w) => this.isWalletSupported(entityToWallet(w)));
|
|
3756
|
-
});
|
|
3757
|
-
}
|
|
3758
|
-
};
|
|
3759
|
-
_authInfo = new WeakMap();
|
|
3760
|
-
_partner = new WeakMap();
|
|
3761
|
-
_ParaCore_instances = new WeakSet();
|
|
3762
|
-
assertPartner_fn = function() {
|
|
3763
|
-
return __async(this, null, function* () {
|
|
3764
|
-
var _a, _b;
|
|
3765
|
-
if (!__privateGet(this, _partner)) {
|
|
3766
|
-
yield this.touchSession();
|
|
3767
|
-
}
|
|
3768
|
-
if (((_a = __privateGet(this, _partner)) == null ? void 0 : _a.cosmosPrefix) && this.ctx.cosmosPrefix !== __privateGet(this, _partner).cosmosPrefix) {
|
|
3769
|
-
this.ctx.cosmosPrefix = (_b = __privateGet(this, _partner)) == null ? void 0 : _b.cosmosPrefix;
|
|
3770
|
-
}
|
|
3771
|
-
return __privateGet(this, _partner);
|
|
3772
|
-
});
|
|
3773
|
-
};
|
|
3774
|
-
toAuthInfo_fn = function({
|
|
3775
|
-
email,
|
|
3776
|
-
phone,
|
|
3777
|
-
countryCode,
|
|
3778
|
-
farcasterUsername,
|
|
3779
|
-
telegramUserId,
|
|
3780
|
-
externalWalletAddress
|
|
3781
|
-
}) {
|
|
3782
|
-
let auth;
|
|
3783
|
-
switch (true) {
|
|
3784
|
-
case !!email:
|
|
3785
|
-
auth = { email };
|
|
3786
|
-
break;
|
|
3787
|
-
case !!phone:
|
|
3788
|
-
{
|
|
3789
|
-
const validPhone = formatPhoneNumber(phone, countryCode);
|
|
3790
|
-
if (validPhone) auth = { phone: formatPhoneNumber(phone, countryCode) };
|
|
3791
|
-
}
|
|
3792
|
-
break;
|
|
3793
|
-
case !!farcasterUsername:
|
|
3794
|
-
auth = { farcasterUsername };
|
|
3795
|
-
break;
|
|
3796
|
-
case !!telegramUserId:
|
|
3797
|
-
auth = { telegramUserId };
|
|
3798
|
-
break;
|
|
3799
|
-
case !!externalWalletAddress:
|
|
3800
|
-
auth = { externalWalletAddress };
|
|
3801
|
-
break;
|
|
3802
|
-
}
|
|
3803
|
-
return extractAuthInfo(auth);
|
|
3804
|
-
};
|
|
3805
|
-
setAuthInfo_fn = function(authInfo) {
|
|
3806
|
-
return __async(this, null, function* () {
|
|
3807
|
-
__privateSet(this, _authInfo, authInfo);
|
|
3808
|
-
yield this.localStorageSetItem(LOCAL_STORAGE_AUTH_INFO, JSON.stringify(authInfo));
|
|
3809
|
-
yield this.localStorageRemoveItem(LOCAL_STORAGE_EMAIL);
|
|
3810
|
-
yield this.localStorageRemoveItem(LOCAL_STORAGE_PHONE);
|
|
3811
|
-
yield this.localStorageRemoveItem(LOCAL_STORAGE_COUNTRY_CODE);
|
|
3812
|
-
yield this.localStorageRemoveItem(LOCAL_STORAGE_FARCASTER_USERNAME);
|
|
3813
|
-
yield this.localStorageRemoveItem(LOCAL_STORAGE_TELEGRAM_USER_ID);
|
|
3814
|
-
});
|
|
3815
|
-
};
|
|
3816
|
-
getPartner_fn = function(partnerId) {
|
|
3817
|
-
return __async(this, null, function* () {
|
|
3818
|
-
const res = yield this.ctx.client.getPartner(partnerId);
|
|
3819
|
-
__privateSet(this, _partner, res.data.partner);
|
|
3820
|
-
return __privateGet(this, _partner);
|
|
3821
|
-
});
|
|
3822
|
-
};
|
|
3823
|
-
prepareAuthState_fn = function(_0) {
|
|
3824
|
-
return __async(this, arguments, function* (serverAuthState, opts = {}) {
|
|
3825
|
-
if (!opts.sessionLookupId && serverAuthState.stage === "login") {
|
|
3826
|
-
opts.sessionLookupId = yield __privateMethod(this, _ParaCore_instances, prepareLogin_fn).call(this);
|
|
3827
|
-
}
|
|
3828
|
-
const { auth, externalWallet, userId, displayName, pfpUrl, username } = serverAuthState;
|
|
3829
|
-
const authInfo = __spreadValues(__spreadValues({}, extractAuthInfo(auth, { isRequired: true })), Object.fromEntries(
|
|
3830
|
-
Object.entries({
|
|
3831
|
-
displayName,
|
|
3832
|
-
pfpUrl,
|
|
3833
|
-
username,
|
|
3834
|
-
externalWallet
|
|
3835
|
-
}).filter(([_, v]) => !!v)
|
|
3836
|
-
));
|
|
3837
|
-
yield __privateMethod(this, _ParaCore_instances, setAuthInfo_fn).call(this, authInfo);
|
|
3838
|
-
yield this.assertIsAuthSet();
|
|
3839
|
-
if (!!externalWallet) {
|
|
3840
|
-
yield this.setExternalWallet(externalWallet);
|
|
3841
|
-
}
|
|
3842
|
-
if (!!userId) {
|
|
3843
|
-
yield this.setUserId(userId);
|
|
3844
|
-
}
|
|
3845
|
-
let authState;
|
|
3846
|
-
switch (serverAuthState.stage) {
|
|
3847
|
-
case "verify":
|
|
3848
|
-
authState = serverAuthState;
|
|
3849
|
-
break;
|
|
3850
|
-
case "login":
|
|
3851
|
-
authState = yield __privateMethod(this, _ParaCore_instances, prepareLoginState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, opts), { sessionLookupId: opts.sessionLookupId }));
|
|
3852
|
-
break;
|
|
3853
|
-
case "signup":
|
|
3854
|
-
authState = yield __privateMethod(this, _ParaCore_instances, prepareSignUpState_fn).call(this, serverAuthState, opts);
|
|
3855
|
-
break;
|
|
3856
|
-
}
|
|
3857
|
-
return authState;
|
|
3858
|
-
});
|
|
3859
|
-
};
|
|
3860
|
-
prepareLogin_fn = function() {
|
|
3861
|
-
return __async(this, null, function* () {
|
|
3862
|
-
yield this.logout();
|
|
3863
|
-
const { sessionLookupId } = yield this.touchSession(true);
|
|
3864
|
-
if (!this.loginEncryptionKeyPair) {
|
|
3865
|
-
yield this.setLoginEncryptionKeyPair();
|
|
3866
|
-
}
|
|
3867
|
-
return sessionLookupId;
|
|
3868
|
-
});
|
|
3869
|
-
};
|
|
3870
|
-
prepareLoginState_fn = function(_0, _1) {
|
|
3871
|
-
return __async(this, arguments, function* (loginState, {
|
|
3872
|
-
useShortUrls: shorten = false,
|
|
3873
|
-
portalTheme,
|
|
3874
|
-
sessionLookupId
|
|
3875
|
-
}) {
|
|
3876
|
-
const _a = loginState, { loginAuthMethods } = _a, authState = __objRest(_a, ["loginAuthMethods"]);
|
|
3877
|
-
return __spreadValues(__spreadValues(__spreadValues({}, authState), !this.isNativePasskey && loginAuthMethods.includes(AuthMethod.PASSKEY) ? {
|
|
3878
|
-
passkeyUrl: yield this.getLoginUrl({ sessionId: sessionLookupId, shorten, portalTheme }),
|
|
3879
|
-
passkeyKnownDeviceUrl: yield this.constructPortalUrl("loginAuth", {
|
|
3880
|
-
sessionId: sessionLookupId,
|
|
3881
|
-
newDevice: {
|
|
3882
|
-
sessionId: sessionLookupId,
|
|
3883
|
-
encryptionKey: getPublicKeyHex(this.loginEncryptionKeyPair)
|
|
3884
|
-
},
|
|
3885
|
-
shorten,
|
|
3886
|
-
portalTheme
|
|
3887
|
-
})
|
|
3888
|
-
} : {}), loginAuthMethods.includes(AuthMethod.PASSWORD) ? {
|
|
3889
|
-
passwordUrl: yield this.constructPortalUrl("loginPassword", {
|
|
3890
|
-
sessionId: sessionLookupId,
|
|
3891
|
-
shorten,
|
|
3892
|
-
portalTheme
|
|
3893
|
-
})
|
|
3894
|
-
} : {});
|
|
3895
|
-
});
|
|
3896
|
-
};
|
|
3897
|
-
prepareSignUpState_fn = function(_0, _1) {
|
|
3898
|
-
return __async(this, arguments, function* (serverSignupState, { useShortUrls: shorten = false, portalTheme }) {
|
|
3899
|
-
const _a = serverSignupState, { signupAuthMethods } = _a, authState = __objRest(_a, ["signupAuthMethods"]);
|
|
3900
|
-
const [isPasskey, isPassword] = [
|
|
3901
|
-
signupAuthMethods.includes(AuthMethod.PASSKEY),
|
|
3902
|
-
signupAuthMethods.includes(AuthMethod.PASSWORD)
|
|
3903
|
-
];
|
|
3904
|
-
if (!isPasskey && !isPassword) {
|
|
3905
|
-
throw new Error(
|
|
3906
|
-
"No supported authentication methods found. Please ensure you have enabled either WebAuth passkeys or passwords in your Developer Portal settings."
|
|
3907
|
-
);
|
|
3908
|
-
}
|
|
3909
|
-
const signupState = authState;
|
|
3910
|
-
if (isPasskey) {
|
|
3911
|
-
const { url: passkeyUrl, credentialId: passkeyId } = yield this.getNewCredentialAndUrl({
|
|
3912
|
-
authMethod: "PASSKEY",
|
|
3913
|
-
shorten
|
|
3914
|
-
});
|
|
3915
|
-
signupState.passkeyUrl = passkeyUrl;
|
|
3916
|
-
signupState.passkeyId = passkeyId;
|
|
3917
|
-
}
|
|
3918
|
-
if (isPassword) {
|
|
3919
|
-
const { url: passwordUrl, credentialId: passwordId } = yield this.getNewCredentialAndUrl({
|
|
3920
|
-
authMethod: "PASSWORD",
|
|
3921
|
-
portalTheme,
|
|
3922
|
-
shorten
|
|
3923
|
-
});
|
|
3924
|
-
signupState.passwordUrl = passwordUrl;
|
|
3925
|
-
signupState.passwordId = passwordId;
|
|
3926
|
-
}
|
|
3927
|
-
return signupState;
|
|
3928
|
-
});
|
|
3929
|
-
};
|
|
3930
|
-
_ParaCore.version = PARA_CORE_VERSION;
|
|
3931
|
-
var ParaCore = _ParaCore;
|
|
3932
|
-
|
|
3933
|
-
// src/index.ts
|
|
3934
|
-
import {
|
|
3935
|
-
AuthMethod as AuthMethod2,
|
|
3936
|
-
EmailTheme as EmailTheme2,
|
|
5
|
+
EmailTheme,
|
|
3937
6
|
Network,
|
|
3938
|
-
WalletType as WalletType3,
|
|
3939
|
-
WalletScheme as WalletScheme3,
|
|
3940
7
|
OnRampAsset,
|
|
3941
8
|
OnRampPurchaseType,
|
|
3942
9
|
OnRampProvider,
|
|
3943
10
|
OnRampPurchaseStatus,
|
|
3944
|
-
OAuthMethod,
|
|
3945
11
|
NON_ED25519,
|
|
3946
|
-
PREGEN_IDENTIFIER_TYPES
|
|
12
|
+
PREGEN_IDENTIFIER_TYPES,
|
|
13
|
+
WALLET_TYPES,
|
|
14
|
+
WALLET_SCHEMES,
|
|
15
|
+
OAUTH_METHODS
|
|
3947
16
|
} from "@getpara/user-management-client";
|
|
3948
|
-
|
|
17
|
+
import {
|
|
18
|
+
OnRampMethod,
|
|
19
|
+
PopupType,
|
|
20
|
+
PregenIdentifierType,
|
|
21
|
+
RecoveryStatus
|
|
22
|
+
} from "./types/index.js";
|
|
23
|
+
export * from "./types/coreApi.js";
|
|
24
|
+
export * from "./types/events.js";
|
|
25
|
+
export * from "./types/config.js";
|
|
26
|
+
import { getPortalDomain, entityToWallet, constructUrl, shortenUrl } from "./utils/index.js";
|
|
27
|
+
import { PREFIX } from "./constants.js";
|
|
28
|
+
import { distributeNewShare } from "./shares/shareDistribution.js";
|
|
29
|
+
import { KeyContainer } from "./shares/KeyContainer.js";
|
|
30
|
+
import { getBaseUrl, initClient } from "./external/userManagementClient.js";
|
|
31
|
+
import * as mpcComputationClient from "./external/mpcComputationClient.js";
|
|
32
|
+
import {
|
|
33
|
+
decryptWithKeyPair,
|
|
34
|
+
decryptWithPrivateKey,
|
|
35
|
+
getAsymmetricKeyPair,
|
|
36
|
+
getPublicKeyHex,
|
|
37
|
+
encryptWithDerivedPublicKey,
|
|
38
|
+
encodePrivateKeyToPemHex,
|
|
39
|
+
getDerivedPrivateKeyAndDecrypt,
|
|
40
|
+
getPublicKeyFromSignature,
|
|
41
|
+
getSHA256HashHex,
|
|
42
|
+
encryptPrivateKey,
|
|
43
|
+
decryptPrivateKey,
|
|
44
|
+
decryptPrivateKeyAndDecryptShare,
|
|
45
|
+
hashPasswordWithSalt,
|
|
46
|
+
encryptPrivateKeyWithPassword,
|
|
47
|
+
decryptPrivateKeyWithPassword,
|
|
48
|
+
publicKeyFromHex
|
|
49
|
+
} from "./cryptography/utils.js";
|
|
50
|
+
export * from "./external/userManagementClient.js";
|
|
51
|
+
export * from "./errors.js";
|
|
52
|
+
export * from "./utils/formatting.js";
|
|
53
|
+
export * from "./utils/polling.js";
|
|
54
|
+
export * from "./utils/phone.js";
|
|
55
|
+
import { isWalletSupported } from "./utils/wallet.js";
|
|
56
|
+
import { getNetworkPrefix, getOnRampAssets, getOnRampNetworks, toAssetInfoArray } from "./utils/onRamps.js";
|
|
57
|
+
import { getPortalBaseURL } from "./utils/url.js";
|
|
58
|
+
import { retrieve } from "./transmission/transmissionUtils.js";
|
|
59
|
+
const paraVersion = ParaCore.version;
|
|
3949
60
|
var src_default = ParaCore;
|
|
3950
61
|
export {
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
EnabledFlow,
|
|
3954
|
-
Environment,
|
|
62
|
+
AuthMethod,
|
|
63
|
+
EmailTheme,
|
|
3955
64
|
KeyContainer,
|
|
3956
65
|
NON_ED25519,
|
|
3957
66
|
Network,
|
|
3958
|
-
|
|
67
|
+
OAUTH_METHODS,
|
|
3959
68
|
OnRampAsset,
|
|
3960
69
|
OnRampMethod,
|
|
3961
70
|
OnRampProvider,
|
|
3962
71
|
OnRampPurchaseStatus,
|
|
3963
72
|
OnRampPurchaseType,
|
|
3964
|
-
PARA_CORE_METHODS,
|
|
3965
73
|
PREGEN_IDENTIFIER_TYPES,
|
|
3966
|
-
ParaEvent,
|
|
3967
74
|
PopupType,
|
|
3968
75
|
PregenIdentifierType,
|
|
3969
76
|
RecoveryStatus,
|
|
3970
77
|
PREFIX as STORAGE_PREFIX,
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
TransactionReviewTimeout,
|
|
3974
|
-
WalletScheme3 as WalletScheme,
|
|
3975
|
-
WalletType3 as WalletType,
|
|
78
|
+
WALLET_SCHEMES,
|
|
79
|
+
WALLET_TYPES,
|
|
3976
80
|
constructUrl,
|
|
3977
|
-
decimalToHex,
|
|
3978
81
|
decryptPrivateKey,
|
|
3979
82
|
decryptPrivateKeyAndDecryptShare,
|
|
3980
83
|
decryptPrivateKeyWithPassword,
|
|
3981
84
|
decryptWithKeyPair,
|
|
3982
85
|
decryptWithPrivateKey,
|
|
3983
86
|
src_default as default,
|
|
3984
|
-
displayPhoneNumber,
|
|
3985
87
|
distributeNewShare,
|
|
3986
88
|
encodePrivateKeyToPemHex,
|
|
3987
89
|
encryptPrivateKey,
|
|
3988
90
|
encryptPrivateKeyWithPassword,
|
|
3989
91
|
encryptWithDerivedPublicKey,
|
|
3990
92
|
entityToWallet,
|
|
3991
|
-
formatPhoneNumber,
|
|
3992
93
|
getAsymmetricKeyPair,
|
|
3993
|
-
getBaseMPCNetworkUrl,
|
|
3994
|
-
getBaseOAuthUrl,
|
|
3995
94
|
getBaseUrl,
|
|
3996
|
-
getCosmosAddress,
|
|
3997
95
|
getDerivedPrivateKeyAndDecrypt,
|
|
96
|
+
getNetworkPrefix,
|
|
3998
97
|
getOnRampAssets,
|
|
3999
98
|
getOnRampNetworks,
|
|
4000
99
|
getPortalBaseURL,
|
|
@@ -4003,18 +102,12 @@ export {
|
|
|
4003
102
|
getPublicKeyHex,
|
|
4004
103
|
getSHA256HashHex,
|
|
4005
104
|
hashPasswordWithSalt,
|
|
4006
|
-
hexStringToBase64,
|
|
4007
|
-
hexToDecimal,
|
|
4008
|
-
hexToSignature,
|
|
4009
|
-
hexToUint8Array,
|
|
4010
105
|
initClient,
|
|
4011
106
|
isWalletSupported,
|
|
4012
|
-
|
|
107
|
+
mpcComputationClient,
|
|
4013
108
|
paraVersion,
|
|
4014
109
|
publicKeyFromHex,
|
|
4015
110
|
shortenUrl,
|
|
4016
111
|
toAssetInfoArray,
|
|
4017
|
-
retrieve as transmissionUtilsRetrieve
|
|
4018
|
-
truncateAddress,
|
|
4019
|
-
waitUntilTrue
|
|
112
|
+
retrieve as transmissionUtilsRetrieve
|
|
4020
113
|
};
|