@imtbl/sdk 0.1.3 → 0.1.5-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/passport.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Configuration, UsersApi, TransfersApi, OrdersApi, ExchangesApi, TradesApi, generateLegacyStarkPrivateKey, createStarkSigner } from '@imtbl/core-sdk';
1
+ import { ImmutableX, Config, generateLegacyStarkPrivateKey, createStarkSigner } from '@imtbl/core-sdk';
2
2
  import { UserManager } from 'oidc-client-ts';
3
3
  import { ethers } from 'ethers';
4
4
  import { Magic } from 'magic-sdk';
@@ -6,6 +6,515 @@ import { OpenIdExtension } from '@magic-ext/oidc';
6
6
  import BN from 'bn.js';
7
7
  import * as encUtils from 'enc-utils';
8
8
 
9
+ var Environment;
10
+ (function (Environment) {
11
+ Environment["PRODUCTION"] = "production";
12
+ Environment["SANDBOX"] = "sandbox";
13
+ })(Environment || (Environment = {}));
14
+
15
+ /**
16
+ * Set `sdkVersion` on config
17
+ */
18
+ const production = () => Config.createConfig({
19
+ basePath: 'https://api.x.immutable.com',
20
+ chainID: 1,
21
+ coreContractAddress: '0x5FDCCA53617f4d2b9134B29090C87D01058e27e9',
22
+ registrationContractAddress: '0x72a06bf2a1CE5e39cBA06c0CAb824960B587d64c',
23
+ sdkVersion: 'ts-immutable-sdk-0.1.5-alpha',
24
+ });
25
+ /**
26
+ * Set `sdkVersion` on config
27
+ */
28
+ const sandbox = () => Config.createConfig({
29
+ basePath: 'https://api.sandbox.x.immutable.com',
30
+ chainID: 5,
31
+ coreContractAddress: '0x7917eDb51ecD6CdB3F9854c3cc593F33de10c623',
32
+ registrationContractAddress: '0x1C97Ada273C9A52253f463042f29117090Cd7D83',
33
+ sdkVersion: 'ts-immutable-sdk-0.1.5-alpha',
34
+ });
35
+ class ImxConfiguration {
36
+ immutableXConfig;
37
+ baseConfig;
38
+ constructor({ baseConfig, overrides }) {
39
+ this.baseConfig = baseConfig;
40
+ if (overrides) {
41
+ this.immutableXConfig = overrides.immutableXConfig;
42
+ }
43
+ else {
44
+ switch (baseConfig.environment) {
45
+ case Environment.SANDBOX: {
46
+ this.immutableXConfig = sandbox();
47
+ break;
48
+ }
49
+ case Environment.PRODUCTION: {
50
+ this.immutableXConfig = production();
51
+ break;
52
+ }
53
+ default: {
54
+ this.immutableXConfig = sandbox();
55
+ }
56
+ }
57
+ }
58
+ }
59
+ }
60
+
61
+ class ImmutableXClient {
62
+ immutableX;
63
+ depositsApi;
64
+ mintsApi;
65
+ ordersApi;
66
+ tokensApi;
67
+ tradesApi;
68
+ transfersApi;
69
+ exchangeApi;
70
+ nftCheckoutPrimaryApi;
71
+ usersApi;
72
+ withdrawalsApi;
73
+ balanceApi;
74
+ assetApi;
75
+ collectionApi;
76
+ metadataApi;
77
+ metadataRefreshesApi;
78
+ projectsApi;
79
+ constructor(config) {
80
+ const imxConfig = new ImxConfiguration(config);
81
+ this.immutableX = new ImmutableX(imxConfig.immutableXConfig);
82
+ this.depositsApi = this.immutableX.depositsApi;
83
+ this.mintsApi = this.immutableX.mintsApi;
84
+ this.ordersApi = this.immutableX.ordersApi;
85
+ this.tokensApi = this.immutableX.tokensApi;
86
+ this.tradesApi = this.immutableX.tradesApi;
87
+ this.transfersApi = this.immutableX.transfersApi;
88
+ this.exchangeApi = this.immutableX.exchangeApi;
89
+ this.usersApi = this.immutableX.usersApi;
90
+ this.withdrawalsApi = this.immutableX.withdrawalsApi;
91
+ this.balanceApi = this.immutableX.balanceApi;
92
+ this.assetApi = this.immutableX.assetApi;
93
+ this.collectionApi = this.immutableX.collectionApi;
94
+ this.metadataApi = this.immutableX.metadataApi;
95
+ this.metadataRefreshesApi = this.immutableX.metadataRefreshesApi;
96
+ this.nftCheckoutPrimaryApi = this.immutableX.nftCheckoutPrimaryApi;
97
+ this.projectsApi = this.immutableX.projectsApi;
98
+ }
99
+ /**
100
+ * Get details of a Deposit with the given ID
101
+ * @param request - the request object containing the parameters to be provided in the API request
102
+ * @returns a promise that resolves with the requested Deposit
103
+ * @throws {@link index.IMXError}
104
+ */
105
+ getDeposit(request) {
106
+ return this.immutableX.getDeposit(request);
107
+ }
108
+ /**
109
+ * Get a list of Deposits
110
+ * @param request - optional object containing the parameters to be provided in the API request
111
+ * @returns a promise that resolves with the requested list of Deposits
112
+ * @throws {@link index.IMXError}
113
+ */
114
+ listDeposits(request) {
115
+ return this.immutableX.listDeposits(request);
116
+ }
117
+ /**
118
+ * Get Stark keys for a registered User
119
+ * @param ethAddress - the eth address of the User
120
+ * @returns a promise that resolves with the requested User
121
+ * @throws {@link index.IMXError}
122
+ */
123
+ getUser(ethAddress) {
124
+ return this.immutableX.getUser(ethAddress);
125
+ }
126
+ /**
127
+ * Get details of an Asset
128
+ * @param request - the request object containing the parameters to be provided in the API request
129
+ * @returns a promise that resolves with the requested Asset
130
+ * @throws {@link index.IMXError}
131
+ */
132
+ getAsset(request) {
133
+ return this.immutableX.getAsset(request);
134
+ }
135
+ /**
136
+ * Get a list of Assets
137
+ * @param request - optional object containing the parameters to be provided in the API request
138
+ * @returns a promise that resolves with the requested list of Assets
139
+ * @throws {@link index.IMXError}
140
+ */
141
+ listAssets(request) {
142
+ return this.immutableX.listAssets(request);
143
+ }
144
+ /**
145
+ * Create a Collection
146
+ * @param ethSigner - the L1 signer
147
+ * @param request - the request object to be provided in the API request
148
+ * @returns a promise that resolves with the created Collection
149
+ * @throws {@link index.IMXError}
150
+ */
151
+ createCollection(ethSigner, request) {
152
+ return this.immutableX.createCollection(ethSigner, request);
153
+ }
154
+ /**
155
+ * Get details of a Collection at the given address
156
+ * @param request - the request object containing the parameters to be provided in the API request
157
+ * @returns a promise that resolves with the requested Collection
158
+ * @throws {@link index.IMXError}
159
+ */
160
+ getCollection(request) {
161
+ return this.immutableX.getCollection(request);
162
+ }
163
+ /**
164
+ * Get a list of Collection filters
165
+ * @param request - the request object containing the parameters to be provided in the API request
166
+ * @returns a promise that resolves with the requested list of Collection Filters
167
+ * @throws {@link index.IMXError}
168
+ */
169
+ listCollectionFilters(request) {
170
+ return this.immutableX.listCollectionFilters(request);
171
+ }
172
+ /**
173
+ * Get a list of Collections
174
+ * @param request - optional object containing the parameters to be provided in the API request
175
+ * @returns a promise that resolves with the requested list of Collections
176
+ * @throws {@link index.IMXError}
177
+ */
178
+ listCollections(request) {
179
+ return this.collectionApi.listCollections(request).then((res) => res.data);
180
+ }
181
+ /**
182
+ * Update a Collection
183
+ * @param ethSigner - the L1 signer
184
+ * @param collectionAddress - the Collection contract address
185
+ * @param request - the request object containing the parameters to be provided in the API request
186
+ * @returns a promise that resolves with the updated Collection
187
+ * @throws {@link index.IMXError}
188
+ */
189
+ updateCollection(ethSigner, collectionAddress, request) {
190
+ return this.immutableX.updateCollection(ethSigner, collectionAddress, request);
191
+ }
192
+ /**
193
+ * Add metadata schema to Collection
194
+ * @param ethSigner - the L1 signer
195
+ * @param collectionAddress - the Collection contract address
196
+ * @param request - the request object containing the parameters to be provided in the API request
197
+ * @returns a promise that resolves with the SuccessResponse if successful
198
+ * @throws {@link index.IMXError}
199
+ */
200
+ addMetadataSchemaToCollection(ethSigner, collectionAddress, request) {
201
+ return this.immutableX.addMetadataSchemaToCollection(ethSigner, collectionAddress, request);
202
+ }
203
+ /**
204
+ * Get Metadata schema
205
+ * @param request - the request object containing the parameters to be provided in the API request
206
+ * @returns a promise that resolves with the requested Metadata schema
207
+ * @throws {@link index.IMXError}
208
+ */
209
+ getMetadataSchema(request) {
210
+ return this.immutableX.getMetadataSchema(request);
211
+ }
212
+ /**
213
+ * Update metadata schema by name
214
+ * @param ethSigner - the L1 signer
215
+ * @param collectionAddress - the Collection contract address
216
+ * @param name - the Metadata schema name
217
+ * @param request - the request object containing the parameters to be provided in the API request
218
+ * @returns a promise that resolves with the SuccessResponse if successful
219
+ * @throws {@link index.IMXError}
220
+ */
221
+ updateMetadataSchemaByName(ethSigner, collectionAddress, name, request) {
222
+ return this.immutableX.updateMetadataSchemaByName(ethSigner, collectionAddress, name, request);
223
+ }
224
+ /**
225
+ * Get a list of metadata refreshes
226
+ * @param ethSigner - the L1 signer
227
+ * @param collectionAddress - the Collection contract address
228
+ * @param pageSize - the page size of the result
229
+ * @param cursor - the cursor
230
+ * @returns a promise that resolves with the requested metadata refreshes
231
+ * @throws {@link index.IMXError}
232
+ */
233
+ listMetadataRefreshes(ethSigner, collectionAddress, pageSize, cursor) {
234
+ return this.immutableX.listMetadataRefreshes(ethSigner, collectionAddress, pageSize, cursor);
235
+ }
236
+ /**
237
+ * Get a list of metadata refresh errors
238
+ * @param ethSigner - the L1 signer
239
+ * @param refreshId - the metadata refresh ID
240
+ * @param pageSize - the page size of the result
241
+ * @param cursor - the cursor
242
+ * @returns a promise that resolves with the requested metadata refresh errors
243
+ * @throws {@link index.IMXError}
244
+ */
245
+ getMetadataRefreshErrors(ethSigner, refreshId, pageSize, cursor) {
246
+ return this.immutableX.getMetadataRefreshErrors(ethSigner, refreshId, pageSize, cursor);
247
+ }
248
+ /**
249
+ * Get a list of metadata refresh results
250
+ * @param ethSigner - the L1 signer
251
+ * @param refreshId - the metadata refresh ID
252
+ * @returns a promise that resolves with the requested metadata refresh results
253
+ * @throws {@link index.IMXError}
254
+ */
255
+ getMetadataRefreshResults(ethSigner, refreshId) {
256
+ return this.immutableX.getMetadataRefreshResults(ethSigner, refreshId);
257
+ }
258
+ /**
259
+ * Request a metadata refresh
260
+ * @param ethSigner - the L1 signer
261
+ * @param request the request object containing the parameters to be provided in the API request
262
+ * @returns a promise that resolves with the requested metadata refresh
263
+ * @throws {@link index.IMXError}
264
+ */
265
+ createMetadataRefresh(ethSigner, request) {
266
+ return this.immutableX.createMetadataRefresh(ethSigner, request);
267
+ }
268
+ /**
269
+ * Create a Project
270
+ * @param ethSigner - the L1 signer
271
+ * @param request - the request object containing the parameters to be provided in the API request
272
+ * @returns a promise that resolves with the created Project
273
+ * @throws {@link index.IMXError}
274
+ */
275
+ async createProject(ethSigner, request) {
276
+ return this.immutableX.createProject(ethSigner, request);
277
+ }
278
+ /**
279
+ * Get a Project
280
+ * @param ethSigner - the L1 signer
281
+ * @param id - the Project ID
282
+ * @returns a promise that resolves with the requested Project
283
+ * @throws {@link index.IMXError}
284
+ */
285
+ async getProject(ethSigner, id) {
286
+ return this.immutableX.getProject(ethSigner, id);
287
+ }
288
+ /**
289
+ * Get Projects owned by the given User
290
+ * @param ethSigner - the L1 signer
291
+ * @param pageSize - the page size of the result
292
+ * @param cursor - the cursor
293
+ * @param orderBy - the property to sort by
294
+ * @param direction - direction to sort (asc/desc)
295
+ * @returns a promise that resolves with the requested Projects
296
+ * @throws {@link index.IMXError}
297
+ */
298
+ async getProjects(ethSigner, pageSize, cursor, orderBy, direction) {
299
+ return this.immutableX.getProjects(ethSigner, pageSize, cursor, orderBy, direction);
300
+ }
301
+ /**
302
+ * Get the token Balances of the User
303
+ * @param request - the request object containing the parameters to be provided in the API request
304
+ * @returns a promise that resolves with the requested Balance
305
+ * @throws {@link index.IMXError}
306
+ */
307
+ getBalance(request) {
308
+ return this.immutableX.getBalance(request);
309
+ }
310
+ /**
311
+ * Get a list of Balances for given User
312
+ * @param request the request object containing the parameters to be provided in the API request
313
+ * @returns a promise that resolves with the requested list of Balances
314
+ * @throws {@link index.IMXError}
315
+ */
316
+ listBalances(request) {
317
+ return this.immutableX.listBalances(request);
318
+ }
319
+ /**
320
+ * Get details of a Mint with the given ID
321
+ * @param request the request object containing the parameters to be provided in the API request
322
+ * @returns a promise that resolves with the requested Mint
323
+ * @throws {@link index.IMXError}
324
+ */
325
+ getMint(request) {
326
+ return this.immutableX.getMint(request);
327
+ }
328
+ /**
329
+ * Get a list of Mints
330
+ * @param request optional object containing the parameters to be provided in the API request
331
+ * @returns a promise that resolves with the requested list of Mints
332
+ * @throws {@link index.IMXError}
333
+ */
334
+ listMints(request) {
335
+ return this.immutableX.listMints(request);
336
+ }
337
+ /**
338
+ * Mint tokens in a batch with fees
339
+ * @param ethSigner - the L1 signer
340
+ * @param request - the request object to be provided in the API request
341
+ * @returns a promise that resolves with the minted tokens
342
+ * @throws {@link index.IMXError}
343
+ */
344
+ mint(ethSigner, request) {
345
+ return this.immutableX.mint(ethSigner, request);
346
+ }
347
+ /**
348
+ * Get a list of Withdrawals
349
+ * @param request - optional object containing the parameters to be provided in the API request
350
+ * @returns a promise that resolves with the requested list of Withdrawals
351
+ * @throws {@link index.IMXError}
352
+ */
353
+ listWithdrawals(request) {
354
+ return this.immutableX.listWithdrawals(request);
355
+ }
356
+ /**
357
+ * Get details of Withdrawal with the given ID
358
+ * @param request - the request object containing the parameters to be provided in the API request
359
+ * @returns a promise that resolves with the requested Withdrawal
360
+ * @throws {@link index.IMXError}
361
+ */
362
+ getWithdrawal(request) {
363
+ return this.immutableX.getWithdrawal(request);
364
+ }
365
+ /**
366
+ * Get details of an Order with the given ID
367
+ * @param request - the request object containing the parameters to be provided in the API request
368
+ * @returns a promise that resolves with the requested Order
369
+ * @throws {@link index.IMXError}
370
+ */
371
+ getOrder(request) {
372
+ return this.immutableX.getOrder(request);
373
+ }
374
+ /**
375
+ * Get a list of Orders
376
+ * @param request - optional object containing the parameters to be provided in the API request
377
+ * @returns a promise that resolves with the requested list of Orders
378
+ * @throws {@link index.IMXError}
379
+ */
380
+ listOrders(request) {
381
+ return this.immutableX.listOrders(request);
382
+ }
383
+ /**
384
+ * Get details of a Trade with the given ID
385
+ * @param request - the request object containing the parameters to be provided in the API request
386
+ * @returns a promise that resolves with the requested Trade
387
+ * @throws {@link index.IMXError}
388
+ */
389
+ getTrade(request) {
390
+ return this.immutableX.getTrade(request);
391
+ }
392
+ /**
393
+ * Get a list of Trades
394
+ * @param request - optional object containing the parameters to be provided in the API request
395
+ * @returns a promise that resolves with the requested list of Trades
396
+ * @throws {@link index.IMXError}
397
+ */
398
+ listTrades(request) {
399
+ return this.immutableX.listTrades(request);
400
+ }
401
+ /**
402
+ * Get details of a Token
403
+ * @param request - the request object containing the parameters to be provided in the API request
404
+ * @returns a promise that resolves with the requested Token
405
+ * @throws {@link index.IMXError}
406
+ */
407
+ getToken(request) {
408
+ return this.immutableX.getToken(request);
409
+ }
410
+ /**
411
+ * Get a list of Tokens
412
+ * @param request - optional object containing the parameters to be provided in the API request
413
+ * @returns a promise that resolves with the requested list of Tokens
414
+ * @throws {@link index.IMXError}
415
+ */
416
+ listTokens(request) {
417
+ return this.immutableX.listTokens(request);
418
+ }
419
+ /**
420
+ * Get details of a Transfer with the given ID
421
+ * @param request - the request object containing the parameters to be provided in the API request
422
+ * @returns a promise that resolves with the requested Transfer
423
+ * @throws {@link index.IMXError}
424
+ */
425
+ getTransfer(request) {
426
+ return this.immutableX.getTransfer(request);
427
+ }
428
+ /**
429
+ * Get a list of Transfers
430
+ * @param request - optional object containing the parameters to be provided in the API request
431
+ * @returns a promise that resolves with the requested list of Transfers
432
+ * @throws {@link index.IMXError}
433
+ */
434
+ listTransfers(request) {
435
+ return this.immutableX.listTransfers(request);
436
+ }
437
+ /**
438
+ * Create a new Exchange transaction
439
+ * @param request - the request object to be provided in the API request
440
+ * @returns a promise that resolves with the created Exchange Transaction
441
+ * @throws {@link index.IMXError}
442
+ */
443
+ createExchange(request) {
444
+ return this.immutableX.createExchange(request).then((res) => res.data);
445
+ }
446
+ /**
447
+ * Get an Exchange transaction
448
+ * @param request - the request object to be provided in the API request
449
+ * @returns a promise that resolves with the Exchange Transaction
450
+ * @throws {@link index.IMXError}
451
+ */
452
+ getExchange(request) {
453
+ return this.immutableX.getExchange(request).then((res) => res.data);
454
+ }
455
+ /**
456
+ * Get Exchange transactions
457
+ * @param request - the request object to be provided in the API request
458
+ * @returns a promise that resolves with Exchange Transactions
459
+ * @throws {@link index.IMXError}
460
+ */
461
+ getExchanges(request) {
462
+ return this.immutableX.getExchanges(request).then((res) => res.data);
463
+ }
464
+ /**
465
+ * Create a new Transfer request
466
+ * @param walletConnection - the pair of Eth/Stark signers
467
+ * @param request - the request object to be provided in the API request
468
+ * @returns a promise that resolves with the created Exchange Transfer
469
+ * @throws {@link index.IMXError}
470
+ */
471
+ exchangeTransfer(walletConnection, request) {
472
+ return this.immutableX.exchangeTransfer(walletConnection, request);
473
+ }
474
+ /**
475
+ * Create a new nft primary transaction
476
+ * @param request - the request object to be provided in the API request
477
+ * @returns a promise that resolves with the created nft primary Transaction
478
+ * @throws {@link index.IMXError}
479
+ */
480
+ createNftPrimary(request) {
481
+ return this.immutableX.createNftPrimary(request).then((res) => res.data);
482
+ }
483
+ /**
484
+ * Get nft primary supported currencies and their limits
485
+ * @param request - the request object to be provided in the API request
486
+ * @returns a promise that resolves with nft primary Currencies
487
+ * @throws {@link index.IMXError}
488
+ */
489
+ getCurrenciesNFTCheckoutPrimary(request) {
490
+ return this.immutableX
491
+ .getCurrenciesNFTCheckoutPrimary(request)
492
+ .then((res) => res.data);
493
+ }
494
+ /**
495
+ * Get nft primary transaction by transaction id
496
+ * @param request - the request object to be provided in the API request
497
+ * @returns a promise that resolves with nft primary transaction
498
+ * @throws {@link index.IMXError}
499
+ */
500
+ getNftPrimaryTransaction(request) {
501
+ return this.immutableX
502
+ .getNftPrimaryTransaction(request)
503
+ .then((res) => res.data);
504
+ }
505
+ /**
506
+ * Get list of nft primary transactions
507
+ * @param request - the request object to be provided in the API request
508
+ * @returns a promise that resolves with nft primary transaction
509
+ * @throws {@link index.IMXError}
510
+ */
511
+ getNftPrimaryTransactions(request) {
512
+ return this.immutableX
513
+ .getNftPrimaryTransactions(request)
514
+ .then((res) => res.data);
515
+ }
516
+ }
517
+
9
518
  // used to sign message with L1 keys. Used for registration
10
519
  function serializeEthSignature(sig) {
11
520
  // This is because golang appends a recovery param
@@ -67,12 +576,6 @@ function convertToSignableToken(token) {
67
576
  }
68
577
  }
69
578
 
70
- var Environment;
71
- (function (Environment) {
72
- Environment["PRODUCTION"] = "production";
73
- Environment["SANDBOX"] = "sandbox";
74
- })(Environment || (Environment = {}));
75
-
76
579
  var PassportErrorType;
77
580
  (function (PassportErrorType) {
78
581
  PassportErrorType["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
@@ -136,9 +639,9 @@ const getAuthConfiguration = ({ oidcConfiguration, authenticationDomain, }) => {
136
639
  authorization_endpoint: `${authenticationDomain}/authorize`,
137
640
  token_endpoint: `${authenticationDomain}/oauth/token`,
138
641
  userinfo_endpoint: `${authenticationDomain}/userinfo`,
139
- end_session_endpoint: `${authenticationDomain}/v2/logout` +
140
- `?returnTo=${encodeURIComponent(oidcConfiguration.logoutRedirectUri)}` +
141
- `&client_id=${oidcConfiguration.clientId}`,
642
+ end_session_endpoint: `${authenticationDomain}/v2/logout`
643
+ + `?returnTo=${encodeURIComponent(oidcConfiguration.logoutRedirectUri)}`
644
+ + `&client_id=${oidcConfiguration.clientId}`,
142
645
  },
143
646
  mergeClaims: true,
144
647
  loadUserInfo: true,
@@ -158,7 +661,7 @@ class AuthManager {
158
661
  this.config = config;
159
662
  this.userManager = new UserManager(getAuthConfiguration(config));
160
663
  }
161
- mapOidcUserToDomainModel = (oidcUser) => {
664
+ static mapOidcUserToDomainModel = (oidcUser) => {
162
665
  const passport = oidcUser.profile?.passport;
163
666
  return {
164
667
  expired: oidcUser.expired,
@@ -179,7 +682,7 @@ class AuthManager {
179
682
  const oidcUser = await this.userManager.signinPopup({
180
683
  popupWindowFeatures,
181
684
  });
182
- return this.mapOidcUserToDomainModel(oidcUser);
685
+ return AuthManager.mapOidcUserToDomainModel(oidcUser);
183
686
  }, PassportErrorType.AUTHENTICATION_ERROR);
184
687
  }
185
688
  async loginCallback() {
@@ -198,7 +701,7 @@ class AuthManager {
198
701
  if (!oidcUser) {
199
702
  return null;
200
703
  }
201
- return this.mapOidcUserToDomainModel(oidcUser);
704
+ return AuthManager.mapOidcUserToDomainModel(oidcUser);
202
705
  }, PassportErrorType.SILENT_LOGIN_ERROR);
203
706
  }
204
707
  async getUser() {
@@ -207,7 +710,7 @@ class AuthManager {
207
710
  if (!oidcUser) {
208
711
  return null;
209
712
  }
210
- return this.mapOidcUserToDomainModel(oidcUser);
713
+ return AuthManager.mapOidcUserToDomainModel(oidcUser);
211
714
  }, PassportErrorType.NOT_LOGGED_IN_ERROR);
212
715
  }
213
716
  async requestRefreshTokenAfterRegistration() {
@@ -215,18 +718,18 @@ class AuthManager {
215
718
  const updatedUser = await retryWithDelay(async () => {
216
719
  const user = await this.userManager.signinSilent();
217
720
  const passportMetadata = user?.profile?.passport;
218
- const metadataExists = !!passportMetadata?.ether_key &&
219
- !!passportMetadata?.stark_key &&
220
- !!passportMetadata?.user_admin_key;
721
+ const metadataExists = !!passportMetadata?.ether_key
722
+ && !!passportMetadata?.stark_key
723
+ && !!passportMetadata?.user_admin_key;
221
724
  if (metadataExists) {
222
725
  return user;
223
726
  }
224
- return Promise.reject('user wallet addresses not exist');
727
+ return Promise.reject(new Error('user wallet addresses not exist'));
225
728
  });
226
729
  if (!updatedUser) {
227
730
  return null;
228
731
  }
229
- return this.mapOidcUserToDomainModel(updatedUser);
732
+ return AuthManager.mapOidcUserToDomainModel(updatedUser);
230
733
  }, PassportErrorType.REFRESH_TOKEN_ERROR);
231
734
  }
232
735
  }
@@ -265,12 +768,24 @@ var SendMessage;
265
768
  })(SendMessage || (SendMessage = {}));
266
769
  var TransactionTypes;
267
770
  (function (TransactionTypes) {
771
+ // TODO: remove this once the naming has been fixed
772
+ // eslint-disable-next-line @typescript-eslint/naming-convention
268
773
  TransactionTypes["CancelOrder"] = "delete:v1/orders";
774
+ // TODO: remove this once the naming has been fixed
775
+ // eslint-disable-next-line @typescript-eslint/naming-convention
269
776
  TransactionTypes["CreateOrder"] = "post:v1/orders";
777
+ // TODO: remove this once the naming has been fixed
778
+ // eslint-disable-next-line @typescript-eslint/naming-convention
270
779
  TransactionTypes["CreateTrade"] = "post:v1/trades";
780
+ // TODO: remove this once the naming has been fixed
781
+ // eslint-disable-next-line @typescript-eslint/naming-convention
271
782
  TransactionTypes["CreateTransfer"] = "post:v1/transfers";
783
+ // TODO: remove this once the naming has been fixed
784
+ // eslint-disable-next-line @typescript-eslint/naming-convention
272
785
  TransactionTypes["CreateBatchTransfer"] = "post:v2/transfers";
273
786
  })(TransactionTypes || (TransactionTypes = {}));
787
+ // TODO: remove this once the naming has been fixed
788
+ // eslint-disable-next-line @typescript-eslint/naming-convention
274
789
  const PassportEventType = 'imx_passport_confirmation';
275
790
 
276
791
  const openPopupCenter = ({ url, title, width, height, }) => {
@@ -290,10 +805,10 @@ const openPopupCenter = ({ url, title, width, height, }) => {
290
805
  return newWindow;
291
806
  };
292
807
 
293
- const ConfirmationWindowTitle = 'Confirm this transaction';
294
- const ConfirmationWindowHeight = 380;
295
- const ConfirmationWindowWidth = 480;
296
- const ConfirmationWindowClosedPollingDuration = 1000;
808
+ const CONFIRMATION_WINDOW_TITLE = 'Confirm this transaction';
809
+ const CONFIRMATION_WINDOW_HEIGHT = 380;
810
+ const CONFIRMATION_WINDOW_WIDTH = 480;
811
+ const CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION = 1000;
297
812
  class ConfirmationScreen {
298
813
  config;
299
814
  constructor(config) {
@@ -309,12 +824,14 @@ class ConfirmationScreen {
309
824
  startTransaction(accessToken, transaction, popupOptions) {
310
825
  return new Promise((resolve, reject) => {
311
826
  const messageHandler = ({ data, origin }) => {
312
- if (origin != this.config.passportDomain ||
313
- data.eventType != PassportEventType) {
827
+ if (origin !== this.config.passportDomain
828
+ || data.eventType !== PassportEventType) {
314
829
  return;
315
830
  }
316
831
  switch (data.messageType) {
317
832
  case ReceiveMessage.CONFIRMATION_WINDOW_READY: {
833
+ // TODO: remove once fixed
834
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
318
835
  this.postMessage(confirmationWindow, accessToken, {
319
836
  messageType: SendMessage.TRANSACTION_START,
320
837
  messageData: transaction,
@@ -336,87 +853,87 @@ class ConfirmationScreen {
336
853
  window.addEventListener('message', messageHandler);
337
854
  const confirmationWindow = openPopupCenter({
338
855
  url: `${this.config.passportDomain}/transaction-confirmation`,
339
- title: ConfirmationWindowTitle,
340
- width: popupOptions?.width || ConfirmationWindowWidth,
341
- height: popupOptions?.height || ConfirmationWindowHeight,
856
+ title: CONFIRMATION_WINDOW_TITLE,
857
+ width: popupOptions?.width || CONFIRMATION_WINDOW_WIDTH,
858
+ height: popupOptions?.height || CONFIRMATION_WINDOW_HEIGHT,
342
859
  });
343
860
  // https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128
344
- const timer = setInterval(function () {
861
+ const timer = setInterval(() => {
345
862
  if (confirmationWindow.closed) {
346
863
  clearInterval(timer);
347
864
  window.removeEventListener('message', messageHandler);
348
865
  resolve({ confirmed: false });
349
866
  }
350
- }, ConfirmationWindowClosedPollingDuration);
867
+ }, CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION);
351
868
  });
352
869
  }
353
870
  }
354
871
 
355
872
  const ERC721$1 = 'ERC721';
356
- const transfer = ({ request, transfersApi, starkSigner, user, passportConfig, }) => {
357
- return withPassportError(async () => {
358
- const transferAmount = request.type === ERC721$1 ? '1' : request.amount;
359
- const getSignableTransferRequest = {
360
- sender: user.etherKey,
361
- token: convertToSignableToken(request),
362
- amount: transferAmount,
363
- receiver: request.receiver,
364
- };
365
- const signableResult = await transfersApi.getSignableTransferV1({
366
- getSignableTransferRequest,
367
- });
368
- const confirmationScreen = new ConfirmationScreen(passportConfig);
369
- const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
370
- transactionType: TransactionTypes.CreateTransfer,
371
- transactionData: getSignableTransferRequest,
372
- });
373
- if (!confirmationResult.confirmed) {
374
- throw new Error('Transaction rejected by user');
375
- }
376
- const signableResultData = signableResult.data;
377
- const { payload_hash: payloadHash } = signableResultData;
378
- const starkSignature = await starkSigner.signMessage(payloadHash);
379
- const senderStarkKey = await starkSigner.getAddress();
380
- const transferSigningParams = {
381
- sender_stark_key: signableResultData.sender_stark_key || senderStarkKey,
382
- sender_vault_id: signableResultData.sender_vault_id,
383
- receiver_stark_key: signableResultData.receiver_stark_key,
384
- receiver_vault_id: signableResultData.receiver_vault_id,
385
- asset_id: signableResultData.asset_id,
386
- amount: signableResultData.amount,
387
- nonce: signableResultData.nonce,
388
- expiration_timestamp: signableResultData.expiration_timestamp,
389
- stark_signature: starkSignature,
390
- };
391
- const createTransferRequest = {
392
- createTransferRequest: transferSigningParams,
393
- };
394
- const headers = {
395
- Authorization: 'Bearer ' + user.accessToken,
396
- };
397
- const { data: responseData } = await transfersApi.createTransferV1(createTransferRequest, { headers });
398
- return {
399
- sent_signature: responseData.sent_signature,
400
- status: responseData.status?.toString(),
401
- time: responseData.time,
402
- transfer_id: responseData.transfer_id,
403
- };
404
- }, PassportErrorType.TRANSFER_ERROR);
405
- };
873
+ const transfer = ({ request, transfersApi, starkSigner, user, passportConfig,
874
+ // TODO: remove this eslint disable once we have a better solution
875
+ // eslint-disable-next-line max-len
876
+ }) => withPassportError(async () => {
877
+ const transferAmount = request.type === ERC721$1 ? '1' : request.amount;
878
+ const getSignableTransferRequest = {
879
+ sender: user.etherKey,
880
+ token: convertToSignableToken(request),
881
+ amount: transferAmount,
882
+ receiver: request.receiver,
883
+ };
884
+ const signableResult = await transfersApi.getSignableTransferV1({
885
+ getSignableTransferRequest,
886
+ });
887
+ const confirmationScreen = new ConfirmationScreen(passportConfig);
888
+ const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
889
+ transactionType: TransactionTypes.CreateTransfer,
890
+ transactionData: getSignableTransferRequest,
891
+ });
892
+ if (!confirmationResult.confirmed) {
893
+ throw new Error('Transaction rejected by user');
894
+ }
895
+ const signableResultData = signableResult.data;
896
+ const { payload_hash: payloadHash } = signableResultData;
897
+ const starkSignature = await starkSigner.signMessage(payloadHash);
898
+ const senderStarkKey = await starkSigner.getAddress();
899
+ const transferSigningParams = {
900
+ sender_stark_key: signableResultData.sender_stark_key || senderStarkKey,
901
+ sender_vault_id: signableResultData.sender_vault_id,
902
+ receiver_stark_key: signableResultData.receiver_stark_key,
903
+ receiver_vault_id: signableResultData.receiver_vault_id,
904
+ asset_id: signableResultData.asset_id,
905
+ amount: signableResultData.amount,
906
+ nonce: signableResultData.nonce,
907
+ expiration_timestamp: signableResultData.expiration_timestamp,
908
+ stark_signature: starkSignature,
909
+ };
910
+ const createTransferRequest = {
911
+ createTransferRequest: transferSigningParams,
912
+ };
913
+ const headers = {
914
+ // eslint-disable-next-line @typescript-eslint/naming-convention
915
+ Authorization: `Bearer ${user.accessToken}`,
916
+ };
917
+ const { data: responseData } = await transfersApi.createTransferV1(createTransferRequest, { headers });
918
+ return {
919
+ sent_signature: responseData.sent_signature,
920
+ status: responseData.status?.toString(),
921
+ time: responseData.time,
922
+ transfer_id: responseData.transfer_id,
923
+ };
924
+ }, PassportErrorType.TRANSFER_ERROR);
406
925
  async function batchNftTransfer({ user, starkSigner, request, transfersApi, passportConfig, }) {
407
926
  return withPassportError(async () => {
408
927
  const ethAddress = user.etherKey;
409
- const signableRequests = request.map((nftTransfer) => {
410
- return {
411
- amount: '1',
412
- token: convertToSignableToken({
413
- type: ERC721$1,
414
- tokenId: nftTransfer.tokenId,
415
- tokenAddress: nftTransfer.tokenAddress,
416
- }),
417
- receiver: nftTransfer.receiver,
418
- };
419
- });
928
+ const signableRequests = request.map((nftTransfer) => ({
929
+ amount: '1',
930
+ token: convertToSignableToken({
931
+ type: ERC721$1,
932
+ tokenId: nftTransfer.tokenId,
933
+ tokenAddress: nftTransfer.tokenAddress,
934
+ }),
935
+ receiver: nftTransfer.receiver,
936
+ }));
420
937
  const getSignableTransferRequestV2 = {
421
938
  sender_ether_key: ethAddress,
422
939
  signable_requests: signableRequests,
@@ -451,7 +968,8 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, pass
451
968
  requests,
452
969
  };
453
970
  const headers = {
454
- Authorization: 'Bearer ' + user.accessToken,
971
+ // eslint-disable-next-line @typescript-eslint/naming-convention
972
+ Authorization: `Bearer ${user.accessToken}`,
455
973
  };
456
974
  const response = await transfersApi.createTransfer({
457
975
  createTransferRequestV2: transferSigningParams,
@@ -508,7 +1026,8 @@ async function createOrder({ starkSigner, user, request, ordersApi, passportConf
508
1026
  },
509
1027
  };
510
1028
  const headers = {
511
- Authorization: 'Bearer ' + user.accessToken,
1029
+ // eslint-disable-next-line @typescript-eslint/naming-convention
1030
+ Authorization: `Bearer ${user.accessToken}`,
512
1031
  };
513
1032
  const createOrderResponse = await ordersApi.createOrder(orderParams, {
514
1033
  headers,
@@ -537,7 +1056,8 @@ async function cancelOrder({ user, starkSigner, request, ordersApi, passportConf
537
1056
  const { payload_hash: payloadHash } = getSignableCancelOrderResponse.data;
538
1057
  const starkSignature = await starkSigner.signMessage(payloadHash);
539
1058
  const headers = {
540
- Authorization: 'Bearer ' + user.accessToken,
1059
+ // eslint-disable-next-line @typescript-eslint/naming-convention
1060
+ Authorization: `Bearer ${user.accessToken}`,
541
1061
  };
542
1062
  const cancelOrderResponse = await ordersApi.cancelOrder({
543
1063
  id: request.order_id.toString(),
@@ -581,7 +1101,8 @@ async function exchangeTransfer({ user, starkSigner, request, exchangesApi, }) {
581
1101
  stark_signature: starkSignature,
582
1102
  };
583
1103
  const headers = {
584
- Authorization: 'Bearer ' + user.accessToken,
1104
+ // eslint-disable-next-line @typescript-eslint/naming-convention
1105
+ Authorization: `Bearer ${user.accessToken}`,
585
1106
  };
586
1107
  const response = await exchangesApi.createExchangeTransfer({
587
1108
  id: request.transactionID,
@@ -637,7 +1158,8 @@ async function createTrade({ request, tradesApi, user, starkSigner, passportConf
637
1158
  vault_id_sell: signableResultData.vault_id_sell,
638
1159
  },
639
1160
  };
640
- const headers = { Authorization: 'Bearer ' + user.accessToken };
1161
+ // eslint-disable-next-line @typescript-eslint/naming-convention
1162
+ const headers = { Authorization: `Bearer ${user.accessToken}` };
641
1163
  const { data: createTradeResponse } = await tradesApi.createTradeV3(tradeParams, {
642
1164
  headers,
643
1165
  });
@@ -648,35 +1170,30 @@ async function createTrade({ request, tradesApi, user, starkSigner, passportConf
648
1170
  class PassportImxProvider {
649
1171
  user;
650
1172
  starkSigner;
651
- transfersApi;
652
- ordersApi;
653
1173
  passportConfig;
654
- exchangesApi;
655
- tradesApi;
656
- constructor({ user, starkSigner, passportConfig }) {
1174
+ immutableXClient;
1175
+ constructor({ user, starkSigner, passportConfig, immutableXClient, }) {
657
1176
  this.user = user;
658
1177
  this.starkSigner = starkSigner;
659
1178
  this.passportConfig = passportConfig;
660
- const apiConfig = new Configuration({
661
- basePath: passportConfig.imxApiBasePath,
662
- });
663
- this.transfersApi = new TransfersApi(apiConfig);
664
- this.ordersApi = new OrdersApi(apiConfig);
665
- this.exchangesApi = new ExchangesApi(apiConfig);
666
- this.tradesApi = new TradesApi(apiConfig);
1179
+ this.immutableXClient = immutableXClient;
667
1180
  }
668
1181
  async transfer(request) {
669
1182
  return transfer({
670
1183
  request,
671
1184
  user: this.user,
672
1185
  starkSigner: this.starkSigner,
673
- transfersApi: this.transfersApi,
1186
+ transfersApi: this.immutableXClient.transfersApi,
674
1187
  passportConfig: this.passportConfig,
675
1188
  });
676
1189
  }
1190
+ // TODO: Remove once implemented
1191
+ // eslint-disable-next-line class-methods-use-this
677
1192
  registerOffchain() {
678
1193
  throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
679
1194
  }
1195
+ // TODO: Remove once implemented
1196
+ // eslint-disable-next-line class-methods-use-this
680
1197
  isRegisteredOnchain() {
681
1198
  throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
682
1199
  }
@@ -685,7 +1202,7 @@ class PassportImxProvider {
685
1202
  request,
686
1203
  user: this.user,
687
1204
  starkSigner: this.starkSigner,
688
- ordersApi: this.ordersApi,
1205
+ ordersApi: this.immutableXClient.ordersApi,
689
1206
  passportConfig: this.passportConfig,
690
1207
  });
691
1208
  }
@@ -694,7 +1211,7 @@ class PassportImxProvider {
694
1211
  request,
695
1212
  user: this.user,
696
1213
  starkSigner: this.starkSigner,
697
- ordersApi: this.ordersApi,
1214
+ ordersApi: this.immutableXClient.ordersApi,
698
1215
  passportConfig: this.passportConfig,
699
1216
  });
700
1217
  }
@@ -703,7 +1220,7 @@ class PassportImxProvider {
703
1220
  request,
704
1221
  user: this.user,
705
1222
  starkSigner: this.starkSigner,
706
- tradesApi: this.tradesApi,
1223
+ tradesApi: this.immutableXClient.tradesApi,
707
1224
  passportConfig: this.passportConfig,
708
1225
  });
709
1226
  }
@@ -712,7 +1229,7 @@ class PassportImxProvider {
712
1229
  request,
713
1230
  user: this.user,
714
1231
  starkSigner: this.starkSigner,
715
- transfersApi: this.transfersApi,
1232
+ transfersApi: this.immutableXClient.transfersApi,
716
1233
  passportConfig: this.passportConfig,
717
1234
  });
718
1235
  }
@@ -721,17 +1238,21 @@ class PassportImxProvider {
721
1238
  request,
722
1239
  user: this.user,
723
1240
  starkSigner: this.starkSigner,
724
- exchangesApi: this.exchangesApi,
1241
+ exchangesApi: this.immutableXClient.exchangeApi,
725
1242
  });
726
1243
  }
727
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1244
+ // TODO: Remove once implemented
1245
+ // eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars
728
1246
  deposit(deposit) {
729
1247
  throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
730
1248
  }
731
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1249
+ // TODO: Remove once implemented
1250
+ // eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars
732
1251
  prepareWithdrawal(request) {
733
1252
  throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
734
1253
  }
1254
+ // TODO: Remove once implemented
1255
+ // eslint-disable-next-line class-methods-use-this
735
1256
  completeWithdrawal(
736
1257
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
737
1258
  starkPublicKey,
@@ -768,7 +1289,6 @@ class PassportConfiguration {
768
1289
  passportDomain;
769
1290
  magicPublishableApiKey;
770
1291
  magicProviderId;
771
- imxApiBasePath;
772
1292
  oidcConfiguration;
773
1293
  baseConfig;
774
1294
  constructor({ baseConfig, overrides, ...oidcConfiguration }) {
@@ -786,33 +1306,30 @@ class PassportConfiguration {
786
1306
  'magicPublishableApiKey',
787
1307
  'magicProviderId',
788
1308
  'passportDomain',
789
- 'imxApiBasePath',
790
1309
  ], 'overrides');
791
1310
  this.network = overrides.network;
792
1311
  this.authenticationDomain = overrides.authenticationDomain;
793
1312
  this.passportDomain = overrides.passportDomain;
794
1313
  this.magicPublishableApiKey = overrides.magicPublishableApiKey;
795
1314
  this.magicProviderId = overrides.magicProviderId;
796
- this.imxApiBasePath = overrides.imxApiBasePath;
797
1315
  }
798
1316
  else {
799
1317
  switch (baseConfig.environment) {
800
- case Environment.SANDBOX: {
801
- this.network = Networks.SANDBOX;
1318
+ case Environment.PRODUCTION: {
1319
+ this.network = Networks.PRODUCTION;
802
1320
  this.authenticationDomain = 'https://auth.immutable.com';
803
1321
  this.magicPublishableApiKey = 'pk_live_10F423798A540ED7';
804
1322
  this.magicProviderId = 'fSMzaRQ4O7p4fttl7pCyGVtJS_G70P8SNsLXtPPGHo0=';
805
- this.passportDomain = 'https://passport.sandbox.immutable.com';
806
- this.imxApiBasePath = 'https://api.sandbox.x.immutable.com';
1323
+ this.passportDomain = 'https://passport.immutable.com';
807
1324
  break;
808
1325
  }
809
- case Environment.PRODUCTION: {
810
- this.network = Networks.PRODUCTION;
1326
+ case Environment.SANDBOX:
1327
+ default: {
1328
+ this.network = Networks.SANDBOX;
811
1329
  this.authenticationDomain = 'https://auth.immutable.com';
812
1330
  this.magicPublishableApiKey = 'pk_live_10F423798A540ED7';
813
1331
  this.magicProviderId = 'fSMzaRQ4O7p4fttl7pCyGVtJS_G70P8SNsLXtPPGHo0=';
814
- this.passportDomain = 'https://passport.immutable.com';
815
- this.imxApiBasePath = 'https://api.x.immutable.com';
1332
+ this.passportDomain = 'https://passport.sandbox.immutable.com';
816
1333
  break;
817
1334
  }
818
1335
  }
@@ -820,12 +1337,12 @@ class PassportConfiguration {
820
1337
  }
821
1338
  }
822
1339
 
823
- const getStarkSigner = async (signer) => {
824
- return withPassportError(async () => {
825
- const privateKey = await generateLegacyStarkPrivateKey(signer);
826
- return createStarkSigner(privateKey);
827
- }, PassportErrorType.WALLET_CONNECTION_ERROR);
828
- };
1340
+ // TODO: remove this eslint disable once we have a better solution
1341
+ // eslint-disable-next-line max-len
1342
+ const getStarkSigner = async (signer) => withPassportError(async () => {
1343
+ const privateKey = await generateLegacyStarkPrivateKey(signer);
1344
+ return createStarkSigner(privateKey);
1345
+ }, PassportErrorType.WALLET_CONNECTION_ERROR);
829
1346
 
830
1347
  async function registerPassport({ ethSigner, starkSigner, usersApi }, authorization) {
831
1348
  return withPassportError(async () => {
@@ -841,7 +1358,7 @@ async function registerPassport({ ethSigner, starkSigner, usersApi }, authorizat
841
1358
  const ethSignature = await signRaw(signableMessage, ethSigner);
842
1359
  const starkSignature = await starkSigner.signMessage(payloadHash);
843
1360
  const response = await usersApi.registerPassportUser({
844
- authorization: `Bearer ` + authorization,
1361
+ authorization: `Bearer ${authorization}`,
845
1362
  registerPassportUserRequest: {
846
1363
  eth_signature: ethSignature,
847
1364
  ether_key: userAddress,
@@ -853,15 +1370,20 @@ async function registerPassport({ ethSigner, starkSigner, usersApi }, authorizat
853
1370
  }, PassportErrorType.USER_REGISTRATION_ERROR);
854
1371
  }
855
1372
 
1373
+ // TODO: Remove this once the dependency has been added
856
1374
  class Passport {
857
1375
  authManager;
858
1376
  magicAdapter;
859
1377
  config;
1378
+ immutableXClient;
860
1379
  constructor(passportModuleConfiguration) {
861
- const passportConfiguration = new PassportConfiguration(passportModuleConfiguration);
862
- this.config = passportConfiguration;
1380
+ this.config = new PassportConfiguration(passportModuleConfiguration);
863
1381
  this.authManager = new AuthManager(this.config);
864
1382
  this.magicAdapter = new MagicAdapter(this.config);
1383
+ this.immutableXClient = passportModuleConfiguration.overrides?.immutableXClient
1384
+ || new ImmutableXClient({
1385
+ baseConfig: passportModuleConfiguration.baseConfig,
1386
+ });
865
1387
  }
866
1388
  async getImxProvider(user) {
867
1389
  if (!user || !user.idToken) {
@@ -876,6 +1398,7 @@ class Passport {
876
1398
  user: updatedUser,
877
1399
  starkSigner,
878
1400
  passportConfig: this.config,
1401
+ immutableXClient: this.immutableXClient,
879
1402
  });
880
1403
  }
881
1404
  const userWithEtherKey = user;
@@ -883,6 +1406,7 @@ class Passport {
883
1406
  user: userWithEtherKey,
884
1407
  starkSigner,
885
1408
  passportConfig: this.config,
1409
+ immutableXClient: this.immutableXClient,
886
1410
  });
887
1411
  }
888
1412
  async connectImxSilent() {
@@ -915,14 +1439,10 @@ class Passport {
915
1439
  return user?.accessToken;
916
1440
  }
917
1441
  async registerUser(userAdminKeySigner, starkSigner, jwt) {
918
- const configuration = new Configuration({
919
- basePath: this.config.imxApiBasePath,
920
- });
921
- const usersApi = new UsersApi(configuration);
922
1442
  await registerPassport({
923
1443
  ethSigner: userAdminKeySigner,
924
1444
  starkSigner,
925
- usersApi,
1445
+ usersApi: this.immutableXClient.usersApi,
926
1446
  }, jwt);
927
1447
  const updatedUser = await this.authManager.requestRefreshTokenAfterRegistration();
928
1448
  if (!updatedUser) {