@getpara/user-management-client 1.8.0 → 2.0.0-alpha.3

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