@getpara/user-management-client 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,770 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
- var __importDefault = (this && this.__importDefault) || function (mod) {
23
- return (mod && mod.__esModule) ? mod : { "default": mod };
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.handleResponseError = exports.handleResponseSuccess = void 0;
27
- const axios_1 = __importDefault(require("axios"));
28
- const qs_1 = __importDefault(require("qs"));
29
- const utils_js_1 = require("./utils.js");
30
- const consts_js_1 = require("./consts.js");
31
- const error_js_1 = require("./error.js");
32
- const handleResponseSuccess = (response) => {
33
- if (response.status === 200) {
34
- return response;
35
- }
36
- throw new error_js_1.ParaApiError('Invalid status code');
37
- };
38
- exports.handleResponseSuccess = handleResponseSuccess;
39
- const handleResponseError = (error) => {
40
- var _a, _b, _c;
41
- if (error === null)
42
- throw new error_js_1.ParaApiError('Error is null');
43
- if (axios_1.default.isAxiosError(error)) {
44
- let message = (_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : 'Unknown error';
45
- // Add meaningful messages to connection errors
46
- // Can do this for other Axios codes as well in the future if we need: https://github.com/axios/axios/blob/v1.x/lib/core/AxiosError.js#L61
47
- if (error.code === 'ERR_NETWORK') {
48
- message = 'Connection error';
49
- }
50
- else if (error.code === 'ERR_CANCELED') {
51
- message = 'Connection canceled';
52
- }
53
- throw new error_js_1.ParaApiError(message, error.code, error.response.status, (_c = error.request) === null || _c === void 0 ? void 0 : _c.responseURL);
54
- }
55
- throw new error_js_1.ParaApiError('Unknown error');
56
- };
57
- exports.handleResponseError = handleResponseError;
58
- class Client {
59
- constructor({ userManagementHost, apiKey, partnerId, version, opts, retrieveSessionCookie, persistSessionCookie, }) {
60
- this.createUser = (body) => __awaiter(this, void 0, void 0, function* () {
61
- const res = yield this.baseRequest.post(`/users`, body);
62
- return res.data;
63
- });
64
- this.checkUserExists = (auth) => __awaiter(this, void 0, void 0, function* () {
65
- const res = yield this.baseRequest.get('/users/exists', {
66
- params: Object.assign({}, auth),
67
- });
68
- return res;
69
- });
70
- this.verifyTelegram = (authObject) => __awaiter(this, void 0, void 0, function* () {
71
- return (yield this.baseRequest.post('/users/telegram', {
72
- authObject,
73
- })).data;
74
- });
75
- this.externalWalletLogin = (body) => __awaiter(this, void 0, void 0, function* () {
76
- const res = yield this.baseRequest.post(`/users/external-wallets/login`, body);
77
- return res.data;
78
- });
79
- // POST /users/:userId/verify-email
80
- this.verifyEmail = (userId, body) => __awaiter(this, void 0, void 0, function* () {
81
- const res = yield this.baseRequest.post(`/users/${userId}/verify-email`, body);
82
- return res;
83
- });
84
- this.verifyPhone = (userId, body) => __awaiter(this, void 0, void 0, function* () {
85
- const res = yield this.baseRequest.post(`/users/${userId}/verify-identifier`, body);
86
- return res;
87
- });
88
- // POST /users/:userId/biometrics/key
89
- this.addSessionPublicKey = (userId, body) => __awaiter(this, void 0, void 0, function* () {
90
- const res = yield this.baseRequest.post(`/users/${userId}/biometrics/key`, body);
91
- return res;
92
- });
93
- // GET /users/:userId/biometrics/keys
94
- this.getSessionPublicKeys = (userId) => __awaiter(this, void 0, void 0, function* () {
95
- const res = yield this.baseRequest.get(`/users/${userId}/biometrics/keys`);
96
- return res;
97
- });
98
- // GET /biometrics/location-hints
99
- this.getBiometricLocationHints = (params) => __awaiter(this, void 0, void 0, function* () {
100
- const res = yield this.baseRequest.get(`/biometrics/location-hints`, { params });
101
- return res.data.hints;
102
- });
103
- // GET /users/:userId/biometrics/:biometricId
104
- this.getSessionPublicKey = (userId, biometricId) => __awaiter(this, void 0, void 0, function* () {
105
- const res = yield this.baseRequest.get(`/users/${userId}/biometrics/${biometricId}`);
106
- return res;
107
- });
108
- // PATCH /users/:userId/biometrics/:biometricId
109
- this.patchSessionPublicKey = (partnerId, userId, biometricId, body) => __awaiter(this, void 0, void 0, function* () {
110
- const res = yield this.baseRequest.patch(`/users/${userId}/biometrics/${biometricId}`, body, {
111
- headers: {
112
- [consts_js_1.PARTNER_ID_HEADER_NAME]: partnerId,
113
- },
114
- });
115
- return res;
116
- });
117
- // GET /biometrics/challenge?email&publicKey
118
- this.getWebChallenge = (auth) => __awaiter(this, void 0, void 0, function* () {
119
- const res = yield this.baseRequest.get('/biometrics/challenge', {
120
- params: Object.assign({}, (auth || {})),
121
- });
122
- return res.data;
123
- });
124
- // POST /touch
125
- this.touchSession = (regenerate) => __awaiter(this, void 0, void 0, function* () {
126
- const res = yield this.baseRequest.post(`/touch?regenerate=${!!regenerate}`);
127
- return res;
128
- });
129
- // GET /session/origin
130
- this.sessionOrigin = (sessionLookupId) => __awaiter(this, void 0, void 0, function* () {
131
- const res = yield this.baseRequest.get(`/sessions/${sessionLookupId}/origin`);
132
- return res.data;
133
- });
134
- // POST /biometrics/verify
135
- this.verifyWebChallenge = (partnerId, body) => __awaiter(this, void 0, void 0, function* () {
136
- const res = yield this.baseRequest.post(`/biometrics/verify`, body, {
137
- headers: {
138
- [consts_js_1.PARTNER_ID_HEADER_NAME]: partnerId,
139
- },
140
- });
141
- return res;
142
- });
143
- // GET /users/:userId/biometrics/challenge
144
- this.getSessionChallenge = (userId) => __awaiter(this, void 0, void 0, function* () {
145
- const res = yield this.baseRequest.get(`/users/${userId}/biometrics/challenge`);
146
- return res;
147
- });
148
- // POST /users/:userId/biometrics/verify
149
- this.verifySessionChallenge = (userId, body) => __awaiter(this, void 0, void 0, function* () {
150
- const res = yield this.baseRequest.post(`/users/${userId}/biometrics/verify`, body);
151
- return res;
152
- });
153
- // POST /users/:userId/wallets
154
- this.createWallet = (userId, body) => __awaiter(this, void 0, void 0, function* () {
155
- const res = yield this.baseRequest.post(`/users/${userId}/wallets`, body);
156
- return res.data;
157
- });
158
- // POST /wallets/pregen
159
- this.createPregenWallet = (body) => __awaiter(this, void 0, void 0, function* () {
160
- const res = yield this.baseRequest.post(`/wallets/pregen`, body);
161
- return res.data;
162
- });
163
- // GET /wallets/pregen?pregenIdentifier={pregenIdentifier}&pregenIdentifierType={pregenIdentifierType}
164
- this.getPregenWallets = (pregenIds_1, ...args_1) => __awaiter(this, [pregenIds_1, ...args_1], void 0, function* (pregenIds, isPortal = false, userId) {
165
- const res = yield this.baseRequest.get('/wallets/pregen', {
166
- params: { ids: pregenIds, expand: isPortal, userId },
167
- });
168
- return res.data;
169
- });
170
- // POST /wallets/pregen/claim
171
- this.claimPregenWallets = (body) => __awaiter(this, void 0, void 0, function* () {
172
- const res = yield this.baseRequest.post(`/wallets/pregen/claim`, body);
173
- return res.data;
174
- });
175
- // POST /users/:userId/wallets/:walletId/transactions/send
176
- this.sendTransaction = (userId, walletId, body) => __awaiter(this, void 0, void 0, function* () {
177
- const res = yield this.baseRequest.post(`/users/${userId}/wallets/${walletId}/transactions/send`, body);
178
- return res;
179
- });
180
- // functionality changed to only sign transactions and not send them
181
- // POST /users/:userId/wallets/:walletId/transactions/sign
182
- this.signTransaction = (userId, walletId, body) => __awaiter(this, void 0, void 0, function* () {
183
- const res = yield this.baseRequest.post(`/users/${userId}/wallets/${walletId}/transactions/sign`, body);
184
- return res;
185
- });
186
- // POST /users/:userId/wallets/:walletId/refresh
187
- this.refreshKeys = (userId, walletId, oldPartnerId, newPartnerId, keyShareProtocolId) => __awaiter(this, void 0, void 0, function* () {
188
- const body = { oldPartnerId, newPartnerId, keyShareProtocolId };
189
- const res = yield this.baseRequest.post(`/users/${userId}/wallets/${walletId}/refresh`, body);
190
- return res;
191
- });
192
- // PATCH /wallets/pregen/:walletId
193
- this.updatePregenWallet = (walletId, body) => __awaiter(this, void 0, void 0, function* () {
194
- const res = yield this.baseRequest.patch(`/wallets/pregen/${walletId}`, body);
195
- return res.data;
196
- });
197
- // GET /users/:userId/wallets
198
- this.getWallets = (userId, includePartnerData) => __awaiter(this, void 0, void 0, function* () {
199
- const res = yield this.baseRequest.get(`/users/${userId}/wallets${includePartnerData ? `?includePartnerData=${encodeURIComponent(includePartnerData)}` : ''}`);
200
- return res;
201
- });
202
- // GET /users/:userId/all-wallets
203
- this.getAllWallets = (userId) => __awaiter(this, void 0, void 0, function* () {
204
- const res = yield this.baseRequest.get(`/users/${userId}/all-wallets`);
205
- return res;
206
- });
207
- // POST /users/:userId/wallets/set
208
- this.setCurrentWalletIds = (userId_1, walletIds_1, ...args_1) => __awaiter(this, [userId_1, walletIds_1, ...args_1], void 0, function* (userId, walletIds, needsWallet = false, sessionLookupId, newDeviceSessionLookupId) {
209
- const res = yield this.baseRequest.post(`/users/${userId}/wallets/set`, {
210
- walletIds,
211
- needsWallet,
212
- sessionLookupId,
213
- newDeviceSessionLookupId,
214
- });
215
- return res;
216
- });
217
- // POST /login
218
- this.login = (props) => __awaiter(this, void 0, void 0, function* () {
219
- const body = props;
220
- const res = yield this.baseRequest.post('/login', body);
221
- return res;
222
- });
223
- // POST /login
224
- this.verifyLogin = (verificationCode) => __awaiter(this, void 0, void 0, function* () {
225
- const body = { verificationCode };
226
- const res = yield this.baseRequest.post('/login/verify-email', body);
227
- return res;
228
- });
229
- // GET /logout
230
- this.logout = () => __awaiter(this, void 0, void 0, function* () {
231
- const res = yield this.baseRequest.get('/logout');
232
- return res;
233
- });
234
- // POST /recovery/verification
235
- this.recoveryVerification = (email, verificationCode) => __awaiter(this, void 0, void 0, function* () {
236
- const body = { email, verificationCode };
237
- const res = yield this.baseRequest.post('/recovery/verification', body);
238
- return res;
239
- });
240
- // POST /recovery
241
- this.recoveryInit = (email) => __awaiter(this, void 0, void 0, function* () {
242
- const body = { email };
243
- const res = yield this.baseRequest.post('/recovery', body);
244
- return res;
245
- });
246
- this.preSignMessage = (userId, walletId, message, scheme, cosmosSignDoc) => __awaiter(this, void 0, void 0, function* () {
247
- const body = { message, scheme, cosmosSignDoc };
248
- const res = yield this.baseRequest.post(`/users/${userId}/wallets/${walletId}/messages/sign`, body);
249
- return res.data;
250
- });
251
- //DELETE /users/:userId
252
- this.deleteSelf = (userId) => __awaiter(this, void 0, void 0, function* () {
253
- const res = yield this.baseRequest.delete(`/users/${userId}`);
254
- return res;
255
- });
256
- // GET /users/:userId/wallets/:walletId/capsule-share
257
- this.getParaShare = (userId, walletId) => __awaiter(this, void 0, void 0, function* () {
258
- const res = yield this.baseRequest.get(`/users/${userId}/wallets/${walletId}/capsule-share`);
259
- return res.data.share;
260
- });
261
- // GET /download-backup-kit/:userId
262
- this.getBackupKit = (userId) => __awaiter(this, void 0, void 0, function* () {
263
- const res = yield this.baseRequest.get(`/download-backup-kit/${userId}`, { responseType: 'blob' });
264
- return res;
265
- });
266
- // PATCH /users/:userId/biometrics/:biometricId
267
- this.patchSessionPassword = (partnerId, userId, passwordId, body) => __awaiter(this, void 0, void 0, function* () {
268
- const res = yield this.baseRequest.patch(`/users/${userId}/passwords/${passwordId}`, body, {
269
- headers: {
270
- [consts_js_1.PARTNER_ID_HEADER_NAME]: partnerId,
271
- },
272
- });
273
- return res;
274
- });
275
- // TODO remove after this is not optional anymore
276
- const headers = Object.assign(Object.assign({}, (apiKey && { [consts_js_1.API_KEY_HEADER_NAME]: apiKey })), (partnerId && { [consts_js_1.PARTNER_ID_HEADER_NAME]: partnerId }));
277
- const axiosConfig = {
278
- baseURL: userManagementHost,
279
- withCredentials: true,
280
- headers,
281
- };
282
- if (retrieveSessionCookie) {
283
- const defaultTransformRequest = Array.isArray(axios_1.default.defaults.transformRequest)
284
- ? axios_1.default.defaults.transformRequest
285
- : [axios_1.default.defaults.transformRequest];
286
- axiosConfig.transformRequest = [
287
- function (data, headers) {
288
- const currentSessionCookie = retrieveSessionCookie();
289
- if (currentSessionCookie) {
290
- headers[consts_js_1.SESSION_COOKIE_HEADER_NAME] = currentSessionCookie;
291
- }
292
- if (version) {
293
- headers[consts_js_1.VERSION_HEADER_NAME] = version;
294
- }
295
- return data;
296
- },
297
- ...defaultTransformRequest,
298
- ];
299
- }
300
- if (persistSessionCookie) {
301
- const defaultTransformResponse = Array.isArray(axios_1.default.defaults.transformResponse)
302
- ? axios_1.default.defaults.transformResponse
303
- : [axios_1.default.defaults.transformResponse];
304
- axiosConfig.transformResponse = [
305
- ...defaultTransformResponse,
306
- function (data, headers, _status) {
307
- if (headers === null || headers === void 0 ? void 0 : headers[consts_js_1.SESSION_COOKIE_HEADER_NAME]) {
308
- persistSessionCookie(headers[consts_js_1.SESSION_COOKIE_HEADER_NAME]);
309
- }
310
- return data;
311
- },
312
- ];
313
- }
314
- this.baseRequest = axios_1.default.create(axiosConfig);
315
- if (opts === null || opts === void 0 ? void 0 : opts.useFetchAdapter) {
316
- axios_1.default.defaults.adapter = function (config) {
317
- return fetch(config.baseURL + config.url.substring(1), {
318
- method: config.method,
319
- headers: config.headers,
320
- body: config.data,
321
- credentials: config.withCredentials ? 'include' : undefined,
322
- })
323
- .then(response => response.text().then(text => ({
324
- data: text,
325
- status: response.status,
326
- statusText: response.statusText,
327
- headers: response.headers,
328
- config: config,
329
- request: fetch,
330
- })))
331
- .catch(function (reason) {
332
- throw reason;
333
- });
334
- };
335
- }
336
- // Intercept response to add more concise errors rather than returning the entire AxiosError
337
- this.baseRequest.interceptors.response.use(exports.handleResponseSuccess, exports.handleResponseError);
338
- }
339
- // DEPRECATED: use uploadUserKeyShares instead
340
- // POST /users/:userId/wallets/:walletId/key-shares
341
- uploadKeyshares(userId, walletId, encryptedKeyshares) {
342
- return __awaiter(this, void 0, void 0, function* () {
343
- const body = { keyShares: encryptedKeyshares };
344
- const res = yield this.baseRequest.post(`/users/${userId}/wallets/${walletId}/key-shares`, body);
345
- return res;
346
- });
347
- }
348
- // POST /users/:userId/key-shares
349
- uploadUserKeyShares(userId, encryptedKeyshares) {
350
- return __awaiter(this, void 0, void 0, function* () {
351
- const body = { keyShares: encryptedKeyshares };
352
- const res = yield this.baseRequest.post(`/users/${userId}/key-shares`, body);
353
- return res;
354
- });
355
- }
356
- // GET /users/:userId/wallets/:walletId/key-shares
357
- getKeyshare(userId, walletId, type, encryptor) {
358
- return __awaiter(this, void 0, void 0, function* () {
359
- const res = yield this.baseRequest.get(`/users/${userId}/wallets/${walletId}/key-shares?type=${type}${encryptor ? `&encryptor=${encryptor}` : ''}`);
360
- return res;
361
- });
362
- }
363
- // GET /users/:userId/biometrics/key-shares
364
- getBiometricKeyshares(userId, biometricPublicKey, getAll) {
365
- return __awaiter(this, void 0, void 0, function* () {
366
- const res = yield this.baseRequest.get(`/users/${userId}/biometrics/key-shares?publicKey=${biometricPublicKey}&all=${!!getAll}`);
367
- return res;
368
- });
369
- }
370
- // GET /users/:userId/key-shares
371
- getPasswordKeyshares(userId, passwordId, getAll) {
372
- return __awaiter(this, void 0, void 0, function* () {
373
- const res = yield this.baseRequest.get(`/users/${userId}/passwords/key-shares?passwordId=${passwordId}&all=${!!getAll}`);
374
- return res;
375
- });
376
- }
377
- // POST '/users/:userId/temporary-shares',
378
- uploadTransmissionKeyshares(userId, shares) {
379
- return __awaiter(this, void 0, void 0, function* () {
380
- const body = { shares };
381
- const res = yield this.baseRequest.post(`/users/${userId}/temporary-shares`, body);
382
- return res;
383
- });
384
- }
385
- // GET /users/:userId/temporary-shares returns { temporaryShares: { userId: string, walletId: string, encryptedShare: string, encryptedKey?: string }[] }
386
- getTransmissionKeyshares(userId, sessionLookupId) {
387
- return __awaiter(this, void 0, void 0, function* () {
388
- const res = yield this.baseRequest.get(`/users/${userId}/temporary-shares?sessionLookupId=${sessionLookupId}`);
389
- return res;
390
- });
391
- }
392
- // POST '/users/:userId/resend-verification-code
393
- resendVerificationCode(_a) {
394
- return __awaiter(this, void 0, void 0, function* () {
395
- var { userId } = _a, rest = __rest(_a, ["userId"]);
396
- const res = yield this.baseRequest.post(`/users/${userId}/resend-verification-code`, rest);
397
- return res;
398
- });
399
- }
400
- // POST '/users/:userId/resend-verification-code-by-phone
401
- resendVerificationCodeByPhone(_a) {
402
- return __awaiter(this, void 0, void 0, function* () {
403
- var { userId } = _a, rest = __rest(_a, ["userId"]);
404
- const res = yield this.baseRequest.post(`/users/${userId}/resend-verification-code-by-phone`, rest);
405
- return res;
406
- });
407
- }
408
- // POST recovery/cancel
409
- cancelRecoveryAttempt(email) {
410
- return __awaiter(this, void 0, void 0, function* () {
411
- const res = yield this.baseRequest.post(`/recovery/cancel`, { email });
412
- return res;
413
- });
414
- }
415
- // GET '/2fa/users/:userId/check-status'
416
- check2FAStatus(userId) {
417
- return __awaiter(this, void 0, void 0, function* () {
418
- const res = yield this.baseRequest.get(`/2fa/users/${userId}/check-status`);
419
- return res;
420
- });
421
- }
422
- // POST '/2fa/users/:userId/enable'
423
- enable2FA(userId, verificationCode) {
424
- return __awaiter(this, void 0, void 0, function* () {
425
- const res = yield this.baseRequest.post(`/2fa/users/${userId}/enable`, { verificationCode });
426
- return res;
427
- });
428
- }
429
- // POST '/2fa/users/:userId/setup'
430
- setup2FA(userId) {
431
- return __awaiter(this, void 0, void 0, function* () {
432
- const res = yield this.baseRequest.post(`/2fa/users/${userId}/setup`);
433
- return res;
434
- });
435
- }
436
- // POST /recovery/init
437
- initializeRecovery(email) {
438
- return __awaiter(this, void 0, void 0, function* () {
439
- const res = yield this.baseRequest.post(`/recovery/init`, { email });
440
- return res;
441
- });
442
- }
443
- // POST /auth/farcaster/init
444
- initializeFarcasterLogin() {
445
- return __awaiter(this, void 0, void 0, function* () {
446
- const res = yield this.baseRequest.post(`/auth/farcaster/init`);
447
- return res;
448
- });
449
- }
450
- // POST /auth/farcaster/status
451
- getFarcasterAuthStatus() {
452
- return __awaiter(this, void 0, void 0, function* () {
453
- const res = yield this.baseRequest.post(`/auth/farcaster/status`);
454
- return res;
455
- });
456
- }
457
- // POST /recovery/init
458
- initializeRecoveryForPhone(phone, countryCode) {
459
- return __awaiter(this, void 0, void 0, function* () {
460
- const res = yield this.baseRequest.post(`/recovery/init`, { phone, countryCode });
461
- return res;
462
- });
463
- }
464
- // POST /recovery/users/:userId/wallets/:walletId/finish
465
- finalizeRecovery(userId, walletId) {
466
- return __awaiter(this, void 0, void 0, function* () {
467
- const res = yield this.baseRequest.post(`/recovery/users/${userId}/wallets/${walletId}/finish`);
468
- return res;
469
- });
470
- }
471
- // GET /recovery/users/:userId/wallets/:walletId/key-shares
472
- recoverUserShares(userId, walletId) {
473
- return __awaiter(this, void 0, void 0, function* () {
474
- const res = yield this.baseRequest.get(`/recovery/users/${userId}/wallets/${walletId}/key-shares?type=USER&encryptor=RECOVERY`);
475
- return res;
476
- });
477
- }
478
- // POST /recovery/verify-email
479
- verifyEmailForRecovery(email, verificationCode) {
480
- return __awaiter(this, void 0, void 0, function* () {
481
- const body = { email, verificationCode };
482
- const res = yield this.baseRequest.post(`/recovery/verify-email`, body);
483
- return res;
484
- });
485
- }
486
- // POST /recovery/verify-identifier
487
- verifyPhoneForRecovery(phone, countryCode, verificationCode) {
488
- return __awaiter(this, void 0, void 0, function* () {
489
- const body = { phone, countryCode, verificationCode };
490
- const res = yield this.baseRequest.post(`/recovery/verify-identifier`, body);
491
- return res;
492
- });
493
- }
494
- // POST /2fa/verify
495
- verify2FA(email, verificationCode) {
496
- return __awaiter(this, void 0, void 0, function* () {
497
- const body = { email, verificationCode };
498
- const res = yield this.baseRequest.post('/2fa/verify', body);
499
- return res;
500
- });
501
- }
502
- // POST /2fa/phone/verify
503
- verify2FAForPhone(phone, countryCode, verificationCode) {
504
- return __awaiter(this, void 0, void 0, function* () {
505
- const body = { phone, countryCode, verificationCode };
506
- const res = yield this.baseRequest.post('/2fa/verify', body);
507
- return res;
508
- });
509
- }
510
- tempTrasmissionInit(message, userId) {
511
- return __awaiter(this, void 0, void 0, function* () {
512
- const body = { message, userId };
513
- const res = yield this.baseRequest.post('/temporary-transmissions', body);
514
- return res;
515
- });
516
- }
517
- tempTrasmission(id) {
518
- return __awaiter(this, void 0, void 0, function* () {
519
- const res = yield this.baseRequest.get(`/temporary-transmissions/${id}`);
520
- return res;
521
- });
522
- }
523
- getPartner(partnerId) {
524
- return __awaiter(this, void 0, void 0, function* () {
525
- const res = yield this.baseRequest.get(`/partners/${partnerId}`);
526
- return res;
527
- });
528
- }
529
- acceptScopes(userId, walletId, body) {
530
- return __awaiter(this, void 0, void 0, function* () {
531
- const res = yield this.baseRequest.post(`/users/${userId}/wallets/${walletId}/scopes/accept`, body);
532
- return res;
533
- });
534
- }
535
- getPendingTransaction(userId, pendingTransactionId) {
536
- return __awaiter(this, void 0, void 0, function* () {
537
- const res = yield this.baseRequest.get(`/users/${userId}/pending-transactions/${pendingTransactionId}`);
538
- return res;
539
- });
540
- }
541
- acceptPendingTransaction(userId, pendingTransactionId) {
542
- return __awaiter(this, void 0, void 0, function* () {
543
- const res = yield this.baseRequest.post(`/users/${userId}/pending-transactions/${pendingTransactionId}/accept`);
544
- return res;
545
- });
546
- }
547
- getOnRampConfig() {
548
- return __awaiter(this, void 0, void 0, function* () {
549
- const res = yield this.baseRequest.get(`/on-ramp-config`);
550
- return res.data;
551
- });
552
- }
553
- createOnRampPurchase(_a) {
554
- return __awaiter(this, void 0, void 0, function* () {
555
- var { userId, params: { type, walletType, address, provider, networks, assets, defaultNetwork, defaultAsset, fiat, fiatQuantity, testMode = false, } } = _a, params = __rest(_a, ["userId", "params"]);
556
- const [key, identifier] = (0, utils_js_1.extractWalletRef)(params);
557
- const walletString = key === 'walletId' ? `wallets/${identifier}` : `external-wallets/${identifier}`;
558
- const res = yield this.baseRequest.post(`/users/${userId}/${walletString}/purchases`, {
559
- type,
560
- provider,
561
- walletType,
562
- address,
563
- networks,
564
- assets,
565
- defaultAsset,
566
- defaultNetwork,
567
- fiat,
568
- fiatQuantity,
569
- testMode,
570
- });
571
- return res.data;
572
- });
573
- }
574
- updateOnRampPurchase(_a) {
575
- return __awaiter(this, void 0, void 0, function* () {
576
- var { userId, purchaseId, updates } = _a, params = __rest(_a, ["userId", "purchaseId", "updates"]);
577
- const [key, identifier] = (0, utils_js_1.extractWalletRef)(params);
578
- const walletString = key === 'walletId' ? `wallets/${identifier}` : `external-wallets/${identifier}`;
579
- const res = yield this.baseRequest.patch(`/users/${userId}/${walletString}/purchases/${purchaseId}`, updates);
580
- return res.data;
581
- });
582
- }
583
- getOnRampPurchase(_a) {
584
- return __awaiter(this, void 0, void 0, function* () {
585
- var { userId, purchaseId } = _a, params = __rest(_a, ["userId", "purchaseId"]);
586
- const [key, identifier] = (0, utils_js_1.extractWalletRef)(params);
587
- const walletString = key === 'walletId' ? `wallets/${identifier}` : `external-wallets/${identifier}`;
588
- const res = yield this.baseRequest.get(`/users/${userId}/${walletString}/purchases/${purchaseId}`);
589
- return res;
590
- });
591
- }
592
- signMoonPayUrl(userId_1, _a) {
593
- return __awaiter(this, arguments, void 0, function* (userId, { url, type, cosmosPrefix, testMode, walletId, externalWalletAddress, }) {
594
- const walletString = walletId ? `wallets/${walletId}` : `external-wallets/${externalWalletAddress}`;
595
- const res = yield this.baseRequest.post(`/users/${userId}/${walletString}/moonpay-sign`, {
596
- url,
597
- type,
598
- cosmosPrefix,
599
- testMode,
600
- });
601
- return res;
602
- });
603
- }
604
- generateOffRampTx(userId_1, _a) {
605
- return __awaiter(this, arguments, void 0, function* (userId, { provider, chainId, contractAddress, testMode, walletId, walletType, destinationAddress, sourceAddress, assetQuantity, }) {
606
- const res = yield this.baseRequest.post(`/users/${userId}/wallets/${walletId}/offramp-generate`, {
607
- provider,
608
- testMode,
609
- chainId,
610
- contractAddress,
611
- walletId,
612
- walletType,
613
- destinationAddress,
614
- sourceAddress,
615
- assetQuantity,
616
- });
617
- return res.data;
618
- });
619
- }
620
- sendOffRampTx(userId_1, _a) {
621
- return __awaiter(this, arguments, void 0, function* (userId, { tx, signature, network, walletId, walletType, }) {
622
- const res = yield this.baseRequest.post(`/users/${userId}/wallets/${walletId}/offramp-send`, {
623
- tx,
624
- signature,
625
- network,
626
- walletType,
627
- });
628
- return res.data;
629
- });
630
- }
631
- distributeParaShare(_a) {
632
- return __awaiter(this, void 0, void 0, function* () {
633
- var { userId, walletId } = _a, rest = __rest(_a, ["userId", "walletId"]);
634
- const body = rest;
635
- const res = yield this.baseRequest.post(`/users/${userId}/wallets/${walletId}/capsule-share/distribute`, body);
636
- return res;
637
- });
638
- }
639
- keepSessionAlive(userId) {
640
- return __awaiter(this, void 0, void 0, function* () {
641
- const res = yield this.baseRequest.post(`/users/${userId}/session/keep-alive`);
642
- return res.data;
643
- });
644
- }
645
- persistRecoveryPublicKeys(userId, publicKeys) {
646
- return __awaiter(this, void 0, void 0, function* () {
647
- const res = yield this.baseRequest.post(`/users/${userId}/recovery-public-keys`, { publicKeys });
648
- return res.data;
649
- });
650
- }
651
- getRecoveryPublicKeys(userId) {
652
- return __awaiter(this, void 0, void 0, function* () {
653
- const res = yield this.baseRequest.get(`/users/${userId}/recovery-public-keys`);
654
- return res.data;
655
- });
656
- }
657
- uploadEncryptedWalletPrivateKey(userId, encryptedWalletPrivateKey, encryptionKeyHash, biometricPublicKey, passwordId) {
658
- return __awaiter(this, void 0, void 0, function* () {
659
- const body = { encryptedWalletPrivateKey, encryptionKeyHash, biometricPublicKey, passwordId };
660
- const res = yield this.baseRequest.post(`/users/${userId}/encrypted-wallet-private-keys`, body);
661
- return res.data;
662
- });
663
- }
664
- getEncryptedWalletPrivateKeys(userId, encryptionKeyHash) {
665
- return __awaiter(this, void 0, void 0, function* () {
666
- const res = yield this.baseRequest.get(`/users/${userId}/encrypted-wallet-private-keys/${encryptionKeyHash}`);
667
- return res.data;
668
- });
669
- }
670
- getConversionRate(chainId, symbol, currency) {
671
- return __awaiter(this, void 0, void 0, function* () {
672
- const params = { symbol, currency };
673
- const res = yield this.baseRequest.get(`/chains/${chainId}/conversion-rate`, { params });
674
- return res.data;
675
- });
676
- }
677
- getGasEstimate(chainId, totalGasPrice) {
678
- return __awaiter(this, void 0, void 0, function* () {
679
- const params = { totalGasPrice };
680
- const res = yield this.baseRequest.get(`/chains/${chainId}/gas-estimate`, { params });
681
- return res.data;
682
- });
683
- }
684
- getGasOracle(chainId) {
685
- return __awaiter(this, void 0, void 0, function* () {
686
- const res = yield this.baseRequest.get(`/chains/${chainId}/gas-oracle`);
687
- return res.data;
688
- });
689
- }
690
- // GET /users/:userId/wallets/:walletId/refresh-done
691
- isRefreshDone(userId, walletId, partnerId, protocolId) {
692
- return __awaiter(this, void 0, void 0, function* () {
693
- const queryParams = {};
694
- if (partnerId)
695
- queryParams['partnerId'] = partnerId;
696
- if (protocolId)
697
- queryParams['protocolId'] = protocolId;
698
- const query = qs_1.default.stringify(queryParams);
699
- const res = yield this.baseRequest.get(`/users/${userId}/wallets/${walletId}/refresh-done?${query}`);
700
- return res.data;
701
- });
702
- }
703
- deletePendingTransaction(userId, pendingTransactionId) {
704
- return __awaiter(this, void 0, void 0, function* () {
705
- const res = yield this.baseRequest.delete(`/users/${userId}/pending-transactions/${pendingTransactionId}`);
706
- return res.data;
707
- });
708
- }
709
- // POST /users/:userId/passwords/key
710
- addSessionPasswordPublicKey(userId, body) {
711
- return __awaiter(this, void 0, void 0, function* () {
712
- const res = yield this.baseRequest.post(`/users/${userId}/passwords/key`, body);
713
- return res;
714
- });
715
- }
716
- getSupportedAuthMethods(auth) {
717
- return __awaiter(this, void 0, void 0, function* () {
718
- const res = yield this.baseRequest.get('/users/supported-auth-methods', {
719
- params: Object.assign({}, auth),
720
- });
721
- return res.data;
722
- });
723
- }
724
- getPasswords(auth) {
725
- return __awaiter(this, void 0, void 0, function* () {
726
- const res = yield this.baseRequest.get('/users/passwords', {
727
- params: Object.assign({}, auth),
728
- });
729
- return res.data.passwords;
730
- });
731
- }
732
- // POST /passwords/verify
733
- verifyPasswordChallenge(partnerId, body) {
734
- return __awaiter(this, void 0, void 0, function* () {
735
- const res = yield this.baseRequest.post(`/passwords/verify`, body, {
736
- headers: {
737
- [consts_js_1.PARTNER_ID_HEADER_NAME]: partnerId,
738
- },
739
- });
740
- return res;
741
- });
742
- }
743
- getEncryptedWalletPrivateKey(passwordId) {
744
- return __awaiter(this, void 0, void 0, function* () {
745
- const queryParams = {};
746
- queryParams['passwordId'] = passwordId;
747
- const query = qs_1.default.stringify(queryParams);
748
- const res = yield this.baseRequest.get(`/encrypted-wallet-private-keys?${query}`);
749
- return res;
750
- });
751
- }
752
- // GET /users/:userId
753
- getUser(userId) {
754
- return __awaiter(this, void 0, void 0, function* () {
755
- const res = yield this.baseRequest.get(`/users/${userId}`);
756
- return res.data;
757
- });
758
- }
759
- }
760
- exports.default = Client;
761
- // GET /users/:userId/wallets/:walletId/send (NOTE: endpoint not found in server)
762
- // NOT USED IN DEMO
763
- // POST /users/:userId/wallets/:walletId/presign
764
- // POST /users/:userId/wallets/:walletId/presign-online
765
- // POST /auth/signup/web
766
- // GET /logout
767
- // POST /users/:userId/wallets/:walletId/key
768
- // GET /users/:userId/wallets/:walletId/key
769
- // GET /users/:userId/configurations
770
- // GET /