@imtbl/sdk 0.28.10 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +147 -0
- package/dist/blockchain_data.d.ts +14 -5
- package/dist/blockchain_data.js +1 -1
- package/dist/browser/checkout.js +2 -2
- package/dist/checkout_sdk.d.ts +14 -5
- package/dist/checkout_sdk.js +2 -20
- package/dist/checkout_widgets.d.ts +14 -5
- package/dist/checkout_widgets.js +1 -1
- package/dist/config.d.ts +18 -6
- package/dist/config.js +21 -20
- package/dist/immutablex_client.d.ts +14 -5
- package/dist/immutablex_client.js +1 -1
- package/dist/index.browser.js +11 -11
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +171 -119
- package/dist/index.d.ts +23 -5
- package/dist/index.js +171 -119
- package/dist/orderbook.d.ts +14 -5
- package/dist/passport.d.ts +14 -5
- package/dist/passport.js +145 -97
- package/dist/provider.d.ts +14 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5,10 +5,10 @@ import jwt_decode from 'jwt-decode';
|
|
|
5
5
|
import * as crypto from 'crypto';
|
|
6
6
|
import { Magic } from 'magic-sdk';
|
|
7
7
|
import { OpenIdExtension } from '@magic-ext/oidc';
|
|
8
|
+
import { JsonRpcProvider, Web3Provider } from '@ethersproject/providers';
|
|
8
9
|
import { BigNumber as BigNumber$1, ethers, providers, constants as constants$1, ContractFactory, utils as utils$1, Contract as Contract$1 } from 'ethers';
|
|
9
10
|
import BN$2 from 'bn.js';
|
|
10
11
|
import * as encUtils from 'enc-utils';
|
|
11
|
-
import { Web3Provider, JsonRpcProvider } from '@ethersproject/providers';
|
|
12
12
|
import { EventEmitter } from 'events';
|
|
13
13
|
import { walletContracts } from '@0xsequence/abi';
|
|
14
14
|
import { encodeSignature, decodeSignature } from '@0xsequence/config';
|
|
@@ -35,34 +35,38 @@ class ImmutableConfiguration {
|
|
|
35
35
|
environment;
|
|
36
36
|
rateLimitingKey;
|
|
37
37
|
apiKey;
|
|
38
|
-
|
|
38
|
+
publishableKey;
|
|
39
39
|
constructor(options) {
|
|
40
40
|
this.environment = options.environment;
|
|
41
|
-
if (options.rateLimitingKey) {
|
|
42
|
-
this.rateLimitingKey = options.rateLimitingKey;
|
|
43
|
-
globalAxios$1.defaults.headers.common['x-api-key'] = this.rateLimitingKey;
|
|
44
|
-
}
|
|
45
|
-
if (options.apiKey) {
|
|
46
|
-
if (!options.apiKey.startsWith('sk_imapik-')) {
|
|
47
|
-
throw new Error('Invalid API key');
|
|
48
|
-
}
|
|
49
|
-
this.apiKey = options.apiKey;
|
|
50
|
-
globalAxios$1.defaults.headers.common['x-immutable-api-key'] = this.apiKey;
|
|
51
|
-
}
|
|
52
|
-
if (options.clientAppId) {
|
|
53
|
-
if (!options.clientAppId.startsWith('cai_imapik-')) {
|
|
54
|
-
throw new Error('Invalid Client App Id');
|
|
55
|
-
}
|
|
56
|
-
this.clientAppId = options.clientAppId;
|
|
57
|
-
globalAxios$1.defaults.headers.common['x-immutable-client-app-id'] = this.clientAppId;
|
|
58
|
-
}
|
|
59
41
|
}
|
|
60
42
|
}
|
|
43
|
+
const API_KEY_PREFIX = 'sk_imapik-';
|
|
44
|
+
const PUBLISHABLE_KEY_PREFIX = 'pk_imapik-';
|
|
45
|
+
const PUBLISHABLE_KEY_LENGTH = 30;
|
|
46
|
+
const addApiKeyToAxiosHeader = (apiKey) => {
|
|
47
|
+
if (!apiKey.startsWith(API_KEY_PREFIX)) {
|
|
48
|
+
throw new Error('Invalid API key. Create your api key in Immutable developer hub. https://hub.immutable.com');
|
|
49
|
+
}
|
|
50
|
+
globalAxios$1.defaults.headers.common['x-immutable-api-key'] = apiKey;
|
|
51
|
+
};
|
|
52
|
+
const addPublishableKeyToAxiosHeader = (publishableKey) => {
|
|
53
|
+
if (!publishableKey.startsWith(PUBLISHABLE_KEY_PREFIX) || publishableKey.length !== PUBLISHABLE_KEY_LENGTH) {
|
|
54
|
+
throw new Error('Invalid Publishable key. Create your Publishable key in Immutable developer hub.'
|
|
55
|
+
+ ' https://hub.immutable.com');
|
|
56
|
+
}
|
|
57
|
+
globalAxios$1.defaults.headers.common['x-immutable-publishable-key'] = publishableKey;
|
|
58
|
+
};
|
|
59
|
+
const addRateLimitingKeyToAxiosHeader = (rateLimitingKey) => {
|
|
60
|
+
globalAxios$1.defaults.headers.common['x-api-key'] = rateLimitingKey;
|
|
61
|
+
};
|
|
61
62
|
|
|
62
63
|
var config = /*#__PURE__*/Object.freeze({
|
|
63
64
|
__proto__: null,
|
|
64
65
|
get Environment () { return Environment$1; },
|
|
65
|
-
ImmutableConfiguration: ImmutableConfiguration
|
|
66
|
+
ImmutableConfiguration: ImmutableConfiguration,
|
|
67
|
+
addApiKeyToAxiosHeader: addApiKeyToAxiosHeader,
|
|
68
|
+
addPublishableKeyToAxiosHeader: addPublishableKeyToAxiosHeader,
|
|
69
|
+
addRateLimitingKeyToAxiosHeader: addRateLimitingKeyToAxiosHeader
|
|
66
70
|
});
|
|
67
71
|
|
|
68
72
|
/* tslint:disable */
|
|
@@ -3629,7 +3633,7 @@ class MultiRollupApiClients {
|
|
|
3629
3633
|
}
|
|
3630
3634
|
|
|
3631
3635
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
3632
|
-
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.
|
|
3636
|
+
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.29.0' };
|
|
3633
3637
|
const createConfig = ({ basePath, headers, }) => {
|
|
3634
3638
|
if (!basePath.trim()) {
|
|
3635
3639
|
throw Error('basePath can not be empty');
|
|
@@ -3689,7 +3693,7 @@ class APIError extends Error {
|
|
|
3689
3693
|
|
|
3690
3694
|
/* eslint-disable implicit-arrow-linebreak */
|
|
3691
3695
|
const defaultHeaders = {
|
|
3692
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.
|
|
3696
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.29.0',
|
|
3693
3697
|
};
|
|
3694
3698
|
/**
|
|
3695
3699
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -4100,7 +4104,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
4100
4104
|
chainID,
|
|
4101
4105
|
coreContractAddress,
|
|
4102
4106
|
registrationContractAddress,
|
|
4103
|
-
sdkVersion: 'ts-immutable-sdk-0.
|
|
4107
|
+
sdkVersion: 'ts-immutable-sdk-0.29.0',
|
|
4104
4108
|
});
|
|
4105
4109
|
/**
|
|
4106
4110
|
* Sets `sdkVersion` at the time of build
|
|
@@ -8755,9 +8759,9 @@ class AuthManager {
|
|
|
8755
8759
|
};
|
|
8756
8760
|
if (passport?.imx_eth_address) {
|
|
8757
8761
|
user.imx = {
|
|
8758
|
-
ethAddress: passport
|
|
8759
|
-
starkAddress: passport
|
|
8760
|
-
userAdminAddress: passport
|
|
8762
|
+
ethAddress: passport.imx_eth_address,
|
|
8763
|
+
starkAddress: passport.imx_stark_address,
|
|
8764
|
+
userAdminAddress: passport.imx_user_admin_address,
|
|
8761
8765
|
};
|
|
8762
8766
|
}
|
|
8763
8767
|
if (passport?.zkevm_eth_address) {
|
|
@@ -8780,11 +8784,11 @@ class AuthManager {
|
|
|
8780
8784
|
nickname: idTokenPayload.nickname,
|
|
8781
8785
|
},
|
|
8782
8786
|
};
|
|
8783
|
-
if (idTokenPayload?.passport
|
|
8787
|
+
if (idTokenPayload?.passport.imx_eth_address) {
|
|
8784
8788
|
user.imx = {
|
|
8785
|
-
ethAddress: idTokenPayload
|
|
8786
|
-
starkAddress: idTokenPayload
|
|
8787
|
-
userAdminAddress: idTokenPayload
|
|
8789
|
+
ethAddress: idTokenPayload.passport.imx_eth_address,
|
|
8790
|
+
starkAddress: idTokenPayload.passport.imx_stark_address,
|
|
8791
|
+
userAdminAddress: idTokenPayload.passport.imx_user_admin_address,
|
|
8788
8792
|
};
|
|
8789
8793
|
}
|
|
8790
8794
|
if (idTokenPayload?.passport?.zkevm_eth_address) {
|
|
@@ -9045,7 +9049,7 @@ class AuthManager {
|
|
|
9045
9049
|
}
|
|
9046
9050
|
}
|
|
9047
9051
|
|
|
9048
|
-
const lazyLoad = (promiseToAwait, initialiseFunction) =>
|
|
9052
|
+
const lazyLoad = (promiseToAwait, initialiseFunction) => promiseToAwait().then(initialiseFunction);
|
|
9049
9053
|
const lazyDocumentReady = (initialiseFunction) => {
|
|
9050
9054
|
const documentReadyPromise = () => new Promise((resolve) => {
|
|
9051
9055
|
if (window.document.readyState === 'complete') {
|
|
@@ -9459,33 +9463,31 @@ async function cancelOrder$1({ user, starkSigner, request, ordersApi, guardianCl
|
|
|
9459
9463
|
}
|
|
9460
9464
|
|
|
9461
9465
|
async function registerPassport({ ethSigner, starkSigner, usersApi }, authorization) {
|
|
9462
|
-
|
|
9463
|
-
|
|
9464
|
-
|
|
9465
|
-
|
|
9466
|
-
|
|
9467
|
-
|
|
9468
|
-
|
|
9469
|
-
|
|
9470
|
-
|
|
9471
|
-
|
|
9472
|
-
|
|
9473
|
-
|
|
9474
|
-
|
|
9475
|
-
|
|
9476
|
-
|
|
9477
|
-
|
|
9478
|
-
|
|
9479
|
-
|
|
9480
|
-
|
|
9481
|
-
|
|
9482
|
-
|
|
9483
|
-
|
|
9484
|
-
|
|
9485
|
-
|
|
9486
|
-
|
|
9487
|
-
return response.statusText;
|
|
9488
|
-
}, PassportErrorType.USER_REGISTRATION_ERROR);
|
|
9466
|
+
const [userAddress, starkPublicKey] = await Promise.all([
|
|
9467
|
+
ethSigner.getAddress(),
|
|
9468
|
+
starkSigner.getAddress(),
|
|
9469
|
+
]);
|
|
9470
|
+
const signableResult = await usersApi.getSignableRegistrationOffchain({
|
|
9471
|
+
getSignableRegistrationRequest: {
|
|
9472
|
+
ether_key: userAddress,
|
|
9473
|
+
stark_key: starkPublicKey,
|
|
9474
|
+
},
|
|
9475
|
+
});
|
|
9476
|
+
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
9477
|
+
const [ethSignature, starkSignature] = await Promise.all([
|
|
9478
|
+
signRaw(signableMessage, ethSigner),
|
|
9479
|
+
starkSigner.signMessage(payloadHash),
|
|
9480
|
+
]);
|
|
9481
|
+
const response = await usersApi.registerPassportUser({
|
|
9482
|
+
authorization: `Bearer ${authorization}`,
|
|
9483
|
+
registerPassportUserRequest: {
|
|
9484
|
+
eth_signature: ethSignature,
|
|
9485
|
+
ether_key: userAddress,
|
|
9486
|
+
stark_signature: starkSignature,
|
|
9487
|
+
stark_key: starkPublicKey,
|
|
9488
|
+
},
|
|
9489
|
+
});
|
|
9490
|
+
return response.data;
|
|
9489
9491
|
}
|
|
9490
9492
|
|
|
9491
9493
|
async function createTrade$1({ request, tradesApi, user, starkSigner, guardianClient, }) {
|
|
@@ -9631,37 +9633,123 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, guar
|
|
|
9631
9633
|
}), PassportErrorType.TRANSFER_ERROR);
|
|
9632
9634
|
}
|
|
9633
9635
|
|
|
9636
|
+
async function forceUserRefresh(authManager) {
|
|
9637
|
+
// User metadata is updated asynchronously. Poll userinfo endpoint until it is updated.
|
|
9638
|
+
await retryWithDelay(async () => {
|
|
9639
|
+
const user = await authManager.loginSilent({ forceRefresh: true }); // force refresh to get updated user info
|
|
9640
|
+
if (user?.imx)
|
|
9641
|
+
return user;
|
|
9642
|
+
return Promise.reject(new Error('user wallet addresses not exist'));
|
|
9643
|
+
});
|
|
9644
|
+
}
|
|
9645
|
+
async function registerOffchain$1(userAdminKeySigner, starkSigner, unregisteredUser, authManager, usersApi) {
|
|
9646
|
+
return withPassportError(async () => {
|
|
9647
|
+
try {
|
|
9648
|
+
const response = await registerPassport({
|
|
9649
|
+
ethSigner: userAdminKeySigner,
|
|
9650
|
+
starkSigner,
|
|
9651
|
+
usersApi,
|
|
9652
|
+
}, unregisteredUser.accessToken);
|
|
9653
|
+
await forceUserRefresh(authManager);
|
|
9654
|
+
return response;
|
|
9655
|
+
}
|
|
9656
|
+
catch (err) {
|
|
9657
|
+
if (globalAxios$1.isAxiosError(err) && err.status === 409) {
|
|
9658
|
+
// The user already registered, but the user token is not updated yet.
|
|
9659
|
+
await forceUserRefresh(authManager);
|
|
9660
|
+
return { tx_hash: '' };
|
|
9661
|
+
}
|
|
9662
|
+
throw err;
|
|
9663
|
+
}
|
|
9664
|
+
}, PassportErrorType.USER_REGISTRATION_ERROR);
|
|
9665
|
+
}
|
|
9666
|
+
|
|
9634
9667
|
class PassportImxProvider {
|
|
9635
9668
|
authManager;
|
|
9636
|
-
starkSigner;
|
|
9637
9669
|
immutableXClient;
|
|
9638
9670
|
guardianClient;
|
|
9639
|
-
|
|
9671
|
+
magicAdapter;
|
|
9672
|
+
/**
|
|
9673
|
+
* This property is set during initialisation and stores the signers in a promise.
|
|
9674
|
+
* This property is not meant to be accessed directly, but through the
|
|
9675
|
+
* `getAuthenticatedUserAndSigners` method.
|
|
9676
|
+
* @see getAuthenticatedUserAndSigners
|
|
9677
|
+
*/
|
|
9678
|
+
signers;
|
|
9679
|
+
signerInitialisationError;
|
|
9680
|
+
constructor({ authManager, immutableXClient, confirmationScreen, config, passportEventEmitter, magicAdapter, }) {
|
|
9640
9681
|
this.authManager = authManager;
|
|
9641
|
-
this.starkSigner = starkSigner;
|
|
9642
9682
|
this.immutableXClient = immutableXClient;
|
|
9643
9683
|
this.guardianClient = new GuardianClient({
|
|
9644
9684
|
confirmationScreen,
|
|
9645
9685
|
config,
|
|
9646
9686
|
});
|
|
9687
|
+
this.magicAdapter = magicAdapter;
|
|
9688
|
+
this.initialiseSigners();
|
|
9647
9689
|
passportEventEmitter.on(PassportEvents.LOGGED_OUT, this.handleLogout);
|
|
9648
9690
|
}
|
|
9649
9691
|
handleLogout = () => {
|
|
9650
|
-
this.
|
|
9692
|
+
this.signers = undefined;
|
|
9651
9693
|
};
|
|
9652
|
-
|
|
9694
|
+
/**
|
|
9695
|
+
* This method is called by the constructor and asynchronously initialises the signers.
|
|
9696
|
+
* The signers are stored in a promise so that they can be retrieved by the provider
|
|
9697
|
+
* when needed.
|
|
9698
|
+
*
|
|
9699
|
+
* If an error is thrown during initialisation, it is stored in the `signerInitialisationError`,
|
|
9700
|
+
* so that it doesn't result in an unhandled promise rejection.
|
|
9701
|
+
*
|
|
9702
|
+
* This error is thrown when the signers are requested through:
|
|
9703
|
+
* @see getAuthenticatedUserAndSigners
|
|
9704
|
+
*
|
|
9705
|
+
*/
|
|
9706
|
+
async initialiseSigners() {
|
|
9707
|
+
const generateSigners = async () => {
|
|
9708
|
+
const user = await this.authManager.getUser();
|
|
9709
|
+
// The user will be present because the factory validates it
|
|
9710
|
+
const magicRpcProvider = await this.magicAdapter.login(user.idToken);
|
|
9711
|
+
const web3Provider = new Web3Provider(magicRpcProvider);
|
|
9712
|
+
const ethSigner = web3Provider.getSigner();
|
|
9713
|
+
const starkSigner = await getStarkSigner(ethSigner);
|
|
9714
|
+
return { ethSigner, starkSigner };
|
|
9715
|
+
};
|
|
9716
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
9717
|
+
this.signers = new Promise(async (resolve) => {
|
|
9718
|
+
try {
|
|
9719
|
+
resolve(await generateSigners());
|
|
9720
|
+
}
|
|
9721
|
+
catch (err) {
|
|
9722
|
+
// Capture and store the initialization error
|
|
9723
|
+
this.signerInitialisationError = err;
|
|
9724
|
+
resolve(undefined);
|
|
9725
|
+
}
|
|
9726
|
+
});
|
|
9727
|
+
}
|
|
9728
|
+
async getAuthenticatedUserAndSigners() {
|
|
9653
9729
|
const user = await this.authManager.getUser();
|
|
9654
|
-
if (!user || this.
|
|
9730
|
+
if (!user || !this.signers) {
|
|
9655
9731
|
throw new PassportError('User has been logged out', PassportErrorType.NOT_LOGGED_IN_ERROR);
|
|
9656
9732
|
}
|
|
9733
|
+
const signers = await this.signers;
|
|
9734
|
+
// Throw the stored error if the signers failed to initialise
|
|
9735
|
+
if (typeof signers === 'undefined') {
|
|
9736
|
+
if (typeof this.signerInitialisationError !== 'undefined') {
|
|
9737
|
+
throw this.signerInitialisationError;
|
|
9738
|
+
}
|
|
9739
|
+
throw new Error('Signers failed to initialise');
|
|
9740
|
+
}
|
|
9741
|
+
return { user, ...signers };
|
|
9742
|
+
}
|
|
9743
|
+
async getRegisteredImxUserAndSigners() {
|
|
9744
|
+
const { user, starkSigner, ethSigner } = await this.getAuthenticatedUserAndSigners();
|
|
9657
9745
|
const isUserImx = (oidcUser) => oidcUser?.imx !== undefined;
|
|
9658
9746
|
if (!isUserImx(user)) {
|
|
9659
9747
|
throw new PassportError('User has not been registered with StarkEx', PassportErrorType.USER_NOT_REGISTERED_ERROR);
|
|
9660
9748
|
}
|
|
9661
|
-
return { user, starkSigner
|
|
9749
|
+
return { user, starkSigner, ethSigner };
|
|
9662
9750
|
}
|
|
9663
9751
|
async transfer(request) {
|
|
9664
|
-
const { user, starkSigner } = await this.
|
|
9752
|
+
const { user, starkSigner } = await this.getRegisteredImxUserAndSigners();
|
|
9665
9753
|
return transfer$1({
|
|
9666
9754
|
request,
|
|
9667
9755
|
user,
|
|
@@ -9670,23 +9758,21 @@ class PassportImxProvider {
|
|
|
9670
9758
|
guardianClient: this.guardianClient,
|
|
9671
9759
|
});
|
|
9672
9760
|
}
|
|
9673
|
-
|
|
9674
|
-
|
|
9675
|
-
|
|
9676
|
-
throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
9761
|
+
async registerOffchain() {
|
|
9762
|
+
const { user, ethSigner, starkSigner } = await this.getAuthenticatedUserAndSigners();
|
|
9763
|
+
return await registerOffchain$1(ethSigner, starkSigner, user, this.authManager, this.immutableXClient.usersApi);
|
|
9677
9764
|
}
|
|
9678
|
-
|
|
9679
|
-
|
|
9680
|
-
|
|
9681
|
-
throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
9765
|
+
async isRegisteredOffchain() {
|
|
9766
|
+
const { user } = await this.getAuthenticatedUserAndSigners();
|
|
9767
|
+
return !!user.imx;
|
|
9682
9768
|
}
|
|
9683
9769
|
// TODO: Remove once implemented
|
|
9684
|
-
// eslint-disable-next-line class-methods-use-this
|
|
9770
|
+
// eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars
|
|
9685
9771
|
isRegisteredOnchain() {
|
|
9686
9772
|
throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
9687
9773
|
}
|
|
9688
9774
|
async createOrder(request) {
|
|
9689
|
-
const { user, starkSigner } = await this.
|
|
9775
|
+
const { user, starkSigner } = await this.getRegisteredImxUserAndSigners();
|
|
9690
9776
|
return createOrder$1({
|
|
9691
9777
|
request,
|
|
9692
9778
|
user,
|
|
@@ -9696,7 +9782,7 @@ class PassportImxProvider {
|
|
|
9696
9782
|
});
|
|
9697
9783
|
}
|
|
9698
9784
|
async cancelOrder(request) {
|
|
9699
|
-
const { user, starkSigner } = await this.
|
|
9785
|
+
const { user, starkSigner } = await this.getRegisteredImxUserAndSigners();
|
|
9700
9786
|
return cancelOrder$1({
|
|
9701
9787
|
request,
|
|
9702
9788
|
user,
|
|
@@ -9706,7 +9792,7 @@ class PassportImxProvider {
|
|
|
9706
9792
|
});
|
|
9707
9793
|
}
|
|
9708
9794
|
async createTrade(request) {
|
|
9709
|
-
const { user, starkSigner } = await this.
|
|
9795
|
+
const { user, starkSigner } = await this.getRegisteredImxUserAndSigners();
|
|
9710
9796
|
return createTrade$1({
|
|
9711
9797
|
request,
|
|
9712
9798
|
user,
|
|
@@ -9716,7 +9802,7 @@ class PassportImxProvider {
|
|
|
9716
9802
|
});
|
|
9717
9803
|
}
|
|
9718
9804
|
async batchNftTransfer(request) {
|
|
9719
|
-
const { user, starkSigner } = await this.
|
|
9805
|
+
const { user, starkSigner } = await this.getRegisteredImxUserAndSigners();
|
|
9720
9806
|
return batchNftTransfer({
|
|
9721
9807
|
request,
|
|
9722
9808
|
user,
|
|
@@ -9726,7 +9812,7 @@ class PassportImxProvider {
|
|
|
9726
9812
|
});
|
|
9727
9813
|
}
|
|
9728
9814
|
async exchangeTransfer(request) {
|
|
9729
|
-
const { user, starkSigner } = await this.
|
|
9815
|
+
const { user, starkSigner } = await this.getRegisteredImxUserAndSigners();
|
|
9730
9816
|
return exchangeTransfer$1({
|
|
9731
9817
|
request,
|
|
9732
9818
|
user,
|
|
@@ -9754,7 +9840,7 @@ class PassportImxProvider {
|
|
|
9754
9840
|
throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
9755
9841
|
}
|
|
9756
9842
|
async getAddress() {
|
|
9757
|
-
const { user } = await this.
|
|
9843
|
+
const { user } = await this.getRegisteredImxUserAndSigners();
|
|
9758
9844
|
return Promise.resolve(user.imx.ethAddress);
|
|
9759
9845
|
}
|
|
9760
9846
|
}
|
|
@@ -9814,49 +9900,15 @@ class PassportImxProviderFactory {
|
|
|
9814
9900
|
if (!user.idToken) {
|
|
9815
9901
|
throw new PassportError('Failed to initialise', PassportErrorType.WALLET_CONNECTION_ERROR);
|
|
9816
9902
|
}
|
|
9817
|
-
const magicRpcProvider = await this.magicAdapter.login(user.idToken);
|
|
9818
|
-
const web3Provider = new Web3Provider(magicRpcProvider);
|
|
9819
|
-
const ethSigner = web3Provider.getSigner();
|
|
9820
|
-
const starkSigner = await getStarkSigner(ethSigner);
|
|
9821
|
-
if (!user.imx?.ethAddress) {
|
|
9822
|
-
await this.registerStarkEx(ethSigner, starkSigner, user.accessToken);
|
|
9823
|
-
return new PassportImxProvider({
|
|
9824
|
-
authManager: this.authManager,
|
|
9825
|
-
starkSigner,
|
|
9826
|
-
immutableXClient: this.immutableXClient,
|
|
9827
|
-
confirmationScreen: this.confirmationScreen,
|
|
9828
|
-
config: this.config,
|
|
9829
|
-
passportEventEmitter: this.passportEventEmitter,
|
|
9830
|
-
});
|
|
9831
|
-
}
|
|
9832
9903
|
return new PassportImxProvider({
|
|
9904
|
+
config: this.config,
|
|
9833
9905
|
authManager: this.authManager,
|
|
9834
|
-
starkSigner,
|
|
9835
9906
|
immutableXClient: this.immutableXClient,
|
|
9836
9907
|
confirmationScreen: this.confirmationScreen,
|
|
9837
|
-
config: this.config,
|
|
9838
9908
|
passportEventEmitter: this.passportEventEmitter,
|
|
9909
|
+
magicAdapter: this.magicAdapter,
|
|
9839
9910
|
});
|
|
9840
9911
|
}
|
|
9841
|
-
async registerStarkEx(userAdminKeySigner, starkSigner, jwt) {
|
|
9842
|
-
return withPassportError(async () => {
|
|
9843
|
-
await registerPassport({
|
|
9844
|
-
ethSigner: userAdminKeySigner,
|
|
9845
|
-
starkSigner,
|
|
9846
|
-
usersApi: this.immutableXClient.usersApi,
|
|
9847
|
-
}, jwt);
|
|
9848
|
-
// User metadata is updated asynchronously. Poll userinfo endpoint until it is updated.
|
|
9849
|
-
const updatedUser = await retryWithDelay(async () => {
|
|
9850
|
-
const user = await this.authManager.loginSilent({ forceRefresh: true }); // force refresh to get updated user info
|
|
9851
|
-
const metadataExists = !!user?.imx;
|
|
9852
|
-
if (metadataExists) {
|
|
9853
|
-
return user;
|
|
9854
|
-
}
|
|
9855
|
-
return Promise.reject(new Error('user wallet addresses not exist'));
|
|
9856
|
-
});
|
|
9857
|
-
return updatedUser;
|
|
9858
|
-
}, PassportErrorType.REFRESH_TOKEN_ERROR);
|
|
9859
|
-
}
|
|
9860
9912
|
}
|
|
9861
9913
|
|
|
9862
9914
|
const validateConfiguration = (configuration, requiredKeys, prefix) => {
|
|
@@ -33648,7 +33700,7 @@ var $045213b18e9f1f94$export$75be0f6af9650f2c;
|
|
|
33648
33700
|
})($045213b18e9f1f94$export$75be0f6af9650f2c || ($045213b18e9f1f94$export$75be0f6af9650f2c = {}));
|
|
33649
33701
|
|
|
33650
33702
|
|
|
33651
|
-
const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.
|
|
33703
|
+
const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.29.0";
|
|
33652
33704
|
const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
|
|
33653
33705
|
const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
|
|
33654
33706
|
|
package/dist/orderbook.d.ts
CHANGED
|
@@ -7,16 +7,25 @@ declare class ImmutableConfiguration {
|
|
|
7
7
|
readonly environment: Environment;
|
|
8
8
|
readonly rateLimitingKey?: string;
|
|
9
9
|
readonly apiKey?: string;
|
|
10
|
-
readonly
|
|
10
|
+
readonly publishableKey?: string;
|
|
11
11
|
constructor(options: {
|
|
12
12
|
environment: Environment;
|
|
13
|
-
rateLimitingKey?: string;
|
|
14
|
-
apiKey?: string;
|
|
15
|
-
clientAppId?: string;
|
|
16
13
|
});
|
|
17
14
|
}
|
|
15
|
+
type ImmutableConfigurationWithRequireableFields<T> = ImmutableConfiguration & (T extends {
|
|
16
|
+
apiKey: 'required';
|
|
17
|
+
} ? Required<{
|
|
18
|
+
apiKey: string;
|
|
19
|
+
}> : {}) & (T extends {
|
|
20
|
+
publishableKey: 'required';
|
|
21
|
+
} ? Required<{
|
|
22
|
+
publishableKey: string;
|
|
23
|
+
}> : {});
|
|
24
|
+
type ImmutableConfigurationWithOmitableFields<T> = (T extends {
|
|
25
|
+
apiKey: 'omit';
|
|
26
|
+
} ? Omit<ImmutableConfigurationWithRequireableFields<T>, 'apiKey'> : ImmutableConfigurationWithRequireableFields<T>);
|
|
18
27
|
interface ModuleConfiguration<T> {
|
|
19
|
-
baseConfig:
|
|
28
|
+
baseConfig: ImmutableConfigurationWithOmitableFields<T>;
|
|
20
29
|
overrides?: T;
|
|
21
30
|
}
|
|
22
31
|
|
package/dist/passport.d.ts
CHANGED
|
@@ -9818,16 +9818,25 @@ declare class ImmutableConfiguration {
|
|
|
9818
9818
|
readonly environment: Environment;
|
|
9819
9819
|
readonly rateLimitingKey?: string;
|
|
9820
9820
|
readonly apiKey?: string;
|
|
9821
|
-
readonly
|
|
9821
|
+
readonly publishableKey?: string;
|
|
9822
9822
|
constructor(options: {
|
|
9823
9823
|
environment: Environment;
|
|
9824
|
-
rateLimitingKey?: string;
|
|
9825
|
-
apiKey?: string;
|
|
9826
|
-
clientAppId?: string;
|
|
9827
9824
|
});
|
|
9828
9825
|
}
|
|
9826
|
+
type ImmutableConfigurationWithRequireableFields<T> = ImmutableConfiguration & (T extends {
|
|
9827
|
+
apiKey: 'required';
|
|
9828
|
+
} ? Required<{
|
|
9829
|
+
apiKey: string;
|
|
9830
|
+
}> : {}) & (T extends {
|
|
9831
|
+
publishableKey: 'required';
|
|
9832
|
+
} ? Required<{
|
|
9833
|
+
publishableKey: string;
|
|
9834
|
+
}> : {});
|
|
9835
|
+
type ImmutableConfigurationWithOmitableFields<T> = (T extends {
|
|
9836
|
+
apiKey: 'omit';
|
|
9837
|
+
} ? Omit<ImmutableConfigurationWithRequireableFields<T>, 'apiKey'> : ImmutableConfigurationWithRequireableFields<T>);
|
|
9829
9838
|
interface ModuleConfiguration<T> {
|
|
9830
|
-
baseConfig:
|
|
9839
|
+
baseConfig: ImmutableConfigurationWithOmitableFields<T>;
|
|
9831
9840
|
overrides?: T;
|
|
9832
9841
|
}
|
|
9833
9842
|
|