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