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