@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.cjs
CHANGED
|
@@ -7,10 +7,10 @@ var jwt_decode = require('jwt-decode');
|
|
|
7
7
|
var crypto = require('crypto');
|
|
8
8
|
var magicSdk = require('magic-sdk');
|
|
9
9
|
var oidc = require('@magic-ext/oidc');
|
|
10
|
+
var providers = require('@ethersproject/providers');
|
|
10
11
|
var ethers = require('ethers');
|
|
11
12
|
var BN$2 = require('bn.js');
|
|
12
13
|
var encUtils = require('enc-utils');
|
|
13
|
-
var providers = require('@ethersproject/providers');
|
|
14
14
|
var events = require('events');
|
|
15
15
|
var abi = require('@0xsequence/abi');
|
|
16
16
|
var config$1 = require('@0xsequence/config');
|
|
@@ -57,34 +57,38 @@ class ImmutableConfiguration {
|
|
|
57
57
|
environment;
|
|
58
58
|
rateLimitingKey;
|
|
59
59
|
apiKey;
|
|
60
|
-
|
|
60
|
+
publishableKey;
|
|
61
61
|
constructor(options) {
|
|
62
62
|
this.environment = options.environment;
|
|
63
|
-
if (options.rateLimitingKey) {
|
|
64
|
-
this.rateLimitingKey = options.rateLimitingKey;
|
|
65
|
-
globalAxios$1.defaults.headers.common['x-api-key'] = this.rateLimitingKey;
|
|
66
|
-
}
|
|
67
|
-
if (options.apiKey) {
|
|
68
|
-
if (!options.apiKey.startsWith('sk_imapik-')) {
|
|
69
|
-
throw new Error('Invalid API key');
|
|
70
|
-
}
|
|
71
|
-
this.apiKey = options.apiKey;
|
|
72
|
-
globalAxios$1.defaults.headers.common['x-immutable-api-key'] = this.apiKey;
|
|
73
|
-
}
|
|
74
|
-
if (options.clientAppId) {
|
|
75
|
-
if (!options.clientAppId.startsWith('cai_imapik-')) {
|
|
76
|
-
throw new Error('Invalid Client App Id');
|
|
77
|
-
}
|
|
78
|
-
this.clientAppId = options.clientAppId;
|
|
79
|
-
globalAxios$1.defaults.headers.common['x-immutable-client-app-id'] = this.clientAppId;
|
|
80
|
-
}
|
|
81
63
|
}
|
|
82
64
|
}
|
|
65
|
+
const API_KEY_PREFIX = 'sk_imapik-';
|
|
66
|
+
const PUBLISHABLE_KEY_PREFIX = 'pk_imapik-';
|
|
67
|
+
const PUBLISHABLE_KEY_LENGTH = 30;
|
|
68
|
+
const addApiKeyToAxiosHeader = (apiKey) => {
|
|
69
|
+
if (!apiKey.startsWith(API_KEY_PREFIX)) {
|
|
70
|
+
throw new Error('Invalid API key. Create your api key in Immutable developer hub. https://hub.immutable.com');
|
|
71
|
+
}
|
|
72
|
+
globalAxios$1.defaults.headers.common['x-immutable-api-key'] = apiKey;
|
|
73
|
+
};
|
|
74
|
+
const addPublishableKeyToAxiosHeader = (publishableKey) => {
|
|
75
|
+
if (!publishableKey.startsWith(PUBLISHABLE_KEY_PREFIX) || publishableKey.length !== PUBLISHABLE_KEY_LENGTH) {
|
|
76
|
+
throw new Error('Invalid Publishable key. Create your Publishable key in Immutable developer hub.'
|
|
77
|
+
+ ' https://hub.immutable.com');
|
|
78
|
+
}
|
|
79
|
+
globalAxios$1.defaults.headers.common['x-immutable-publishable-key'] = publishableKey;
|
|
80
|
+
};
|
|
81
|
+
const addRateLimitingKeyToAxiosHeader = (rateLimitingKey) => {
|
|
82
|
+
globalAxios$1.defaults.headers.common['x-api-key'] = rateLimitingKey;
|
|
83
|
+
};
|
|
83
84
|
|
|
84
85
|
var config = /*#__PURE__*/Object.freeze({
|
|
85
86
|
__proto__: null,
|
|
86
87
|
get Environment () { return Environment$1; },
|
|
87
|
-
ImmutableConfiguration: ImmutableConfiguration
|
|
88
|
+
ImmutableConfiguration: ImmutableConfiguration,
|
|
89
|
+
addApiKeyToAxiosHeader: addApiKeyToAxiosHeader,
|
|
90
|
+
addPublishableKeyToAxiosHeader: addPublishableKeyToAxiosHeader,
|
|
91
|
+
addRateLimitingKeyToAxiosHeader: addRateLimitingKeyToAxiosHeader
|
|
88
92
|
});
|
|
89
93
|
|
|
90
94
|
/* tslint:disable */
|
|
@@ -3651,7 +3655,7 @@ class MultiRollupApiClients {
|
|
|
3651
3655
|
}
|
|
3652
3656
|
|
|
3653
3657
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
3654
|
-
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.
|
|
3658
|
+
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.29.0' };
|
|
3655
3659
|
const createConfig = ({ basePath, headers, }) => {
|
|
3656
3660
|
if (!basePath.trim()) {
|
|
3657
3661
|
throw Error('basePath can not be empty');
|
|
@@ -3711,7 +3715,7 @@ class APIError extends Error {
|
|
|
3711
3715
|
|
|
3712
3716
|
/* eslint-disable implicit-arrow-linebreak */
|
|
3713
3717
|
const defaultHeaders = {
|
|
3714
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.
|
|
3718
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.29.0',
|
|
3715
3719
|
};
|
|
3716
3720
|
/**
|
|
3717
3721
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -4122,7 +4126,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
4122
4126
|
chainID,
|
|
4123
4127
|
coreContractAddress,
|
|
4124
4128
|
registrationContractAddress,
|
|
4125
|
-
sdkVersion: 'ts-immutable-sdk-0.
|
|
4129
|
+
sdkVersion: 'ts-immutable-sdk-0.29.0',
|
|
4126
4130
|
});
|
|
4127
4131
|
/**
|
|
4128
4132
|
* Sets `sdkVersion` at the time of build
|
|
@@ -8777,9 +8781,9 @@ class AuthManager {
|
|
|
8777
8781
|
};
|
|
8778
8782
|
if (passport?.imx_eth_address) {
|
|
8779
8783
|
user.imx = {
|
|
8780
|
-
ethAddress: passport
|
|
8781
|
-
starkAddress: passport
|
|
8782
|
-
userAdminAddress: passport
|
|
8784
|
+
ethAddress: passport.imx_eth_address,
|
|
8785
|
+
starkAddress: passport.imx_stark_address,
|
|
8786
|
+
userAdminAddress: passport.imx_user_admin_address,
|
|
8783
8787
|
};
|
|
8784
8788
|
}
|
|
8785
8789
|
if (passport?.zkevm_eth_address) {
|
|
@@ -8802,11 +8806,11 @@ class AuthManager {
|
|
|
8802
8806
|
nickname: idTokenPayload.nickname,
|
|
8803
8807
|
},
|
|
8804
8808
|
};
|
|
8805
|
-
if (idTokenPayload?.passport
|
|
8809
|
+
if (idTokenPayload?.passport.imx_eth_address) {
|
|
8806
8810
|
user.imx = {
|
|
8807
|
-
ethAddress: idTokenPayload
|
|
8808
|
-
starkAddress: idTokenPayload
|
|
8809
|
-
userAdminAddress: idTokenPayload
|
|
8811
|
+
ethAddress: idTokenPayload.passport.imx_eth_address,
|
|
8812
|
+
starkAddress: idTokenPayload.passport.imx_stark_address,
|
|
8813
|
+
userAdminAddress: idTokenPayload.passport.imx_user_admin_address,
|
|
8810
8814
|
};
|
|
8811
8815
|
}
|
|
8812
8816
|
if (idTokenPayload?.passport?.zkevm_eth_address) {
|
|
@@ -9067,7 +9071,7 @@ class AuthManager {
|
|
|
9067
9071
|
}
|
|
9068
9072
|
}
|
|
9069
9073
|
|
|
9070
|
-
const lazyLoad = (promiseToAwait, initialiseFunction) =>
|
|
9074
|
+
const lazyLoad = (promiseToAwait, initialiseFunction) => promiseToAwait().then(initialiseFunction);
|
|
9071
9075
|
const lazyDocumentReady = (initialiseFunction) => {
|
|
9072
9076
|
const documentReadyPromise = () => new Promise((resolve) => {
|
|
9073
9077
|
if (window.document.readyState === 'complete') {
|
|
@@ -9481,33 +9485,31 @@ async function cancelOrder$1({ user, starkSigner, request, ordersApi, guardianCl
|
|
|
9481
9485
|
}
|
|
9482
9486
|
|
|
9483
9487
|
async function registerPassport({ ethSigner, starkSigner, usersApi }, authorization) {
|
|
9484
|
-
|
|
9485
|
-
|
|
9486
|
-
|
|
9487
|
-
|
|
9488
|
-
|
|
9489
|
-
|
|
9490
|
-
|
|
9491
|
-
|
|
9492
|
-
|
|
9493
|
-
|
|
9494
|
-
|
|
9495
|
-
|
|
9496
|
-
|
|
9497
|
-
|
|
9498
|
-
|
|
9499
|
-
|
|
9500
|
-
|
|
9501
|
-
|
|
9502
|
-
|
|
9503
|
-
|
|
9504
|
-
|
|
9505
|
-
|
|
9506
|
-
|
|
9507
|
-
|
|
9508
|
-
|
|
9509
|
-
return response.statusText;
|
|
9510
|
-
}, PassportErrorType.USER_REGISTRATION_ERROR);
|
|
9488
|
+
const [userAddress, starkPublicKey] = await Promise.all([
|
|
9489
|
+
ethSigner.getAddress(),
|
|
9490
|
+
starkSigner.getAddress(),
|
|
9491
|
+
]);
|
|
9492
|
+
const signableResult = await usersApi.getSignableRegistrationOffchain({
|
|
9493
|
+
getSignableRegistrationRequest: {
|
|
9494
|
+
ether_key: userAddress,
|
|
9495
|
+
stark_key: starkPublicKey,
|
|
9496
|
+
},
|
|
9497
|
+
});
|
|
9498
|
+
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
9499
|
+
const [ethSignature, starkSignature] = await Promise.all([
|
|
9500
|
+
signRaw(signableMessage, ethSigner),
|
|
9501
|
+
starkSigner.signMessage(payloadHash),
|
|
9502
|
+
]);
|
|
9503
|
+
const response = await usersApi.registerPassportUser({
|
|
9504
|
+
authorization: `Bearer ${authorization}`,
|
|
9505
|
+
registerPassportUserRequest: {
|
|
9506
|
+
eth_signature: ethSignature,
|
|
9507
|
+
ether_key: userAddress,
|
|
9508
|
+
stark_signature: starkSignature,
|
|
9509
|
+
stark_key: starkPublicKey,
|
|
9510
|
+
},
|
|
9511
|
+
});
|
|
9512
|
+
return response.data;
|
|
9511
9513
|
}
|
|
9512
9514
|
|
|
9513
9515
|
async function createTrade$1({ request, tradesApi, user, starkSigner, guardianClient, }) {
|
|
@@ -9653,37 +9655,123 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, guar
|
|
|
9653
9655
|
}), PassportErrorType.TRANSFER_ERROR);
|
|
9654
9656
|
}
|
|
9655
9657
|
|
|
9658
|
+
async function forceUserRefresh(authManager) {
|
|
9659
|
+
// User metadata is updated asynchronously. Poll userinfo endpoint until it is updated.
|
|
9660
|
+
await retryWithDelay(async () => {
|
|
9661
|
+
const user = await authManager.loginSilent({ forceRefresh: true }); // force refresh to get updated user info
|
|
9662
|
+
if (user?.imx)
|
|
9663
|
+
return user;
|
|
9664
|
+
return Promise.reject(new Error('user wallet addresses not exist'));
|
|
9665
|
+
});
|
|
9666
|
+
}
|
|
9667
|
+
async function registerOffchain$1(userAdminKeySigner, starkSigner, unregisteredUser, authManager, usersApi) {
|
|
9668
|
+
return withPassportError(async () => {
|
|
9669
|
+
try {
|
|
9670
|
+
const response = await registerPassport({
|
|
9671
|
+
ethSigner: userAdminKeySigner,
|
|
9672
|
+
starkSigner,
|
|
9673
|
+
usersApi,
|
|
9674
|
+
}, unregisteredUser.accessToken);
|
|
9675
|
+
await forceUserRefresh(authManager);
|
|
9676
|
+
return response;
|
|
9677
|
+
}
|
|
9678
|
+
catch (err) {
|
|
9679
|
+
if (globalAxios$1.isAxiosError(err) && err.status === 409) {
|
|
9680
|
+
// The user already registered, but the user token is not updated yet.
|
|
9681
|
+
await forceUserRefresh(authManager);
|
|
9682
|
+
return { tx_hash: '' };
|
|
9683
|
+
}
|
|
9684
|
+
throw err;
|
|
9685
|
+
}
|
|
9686
|
+
}, PassportErrorType.USER_REGISTRATION_ERROR);
|
|
9687
|
+
}
|
|
9688
|
+
|
|
9656
9689
|
class PassportImxProvider {
|
|
9657
9690
|
authManager;
|
|
9658
|
-
starkSigner;
|
|
9659
9691
|
immutableXClient;
|
|
9660
9692
|
guardianClient;
|
|
9661
|
-
|
|
9693
|
+
magicAdapter;
|
|
9694
|
+
/**
|
|
9695
|
+
* This property is set during initialisation and stores the signers in a promise.
|
|
9696
|
+
* This property is not meant to be accessed directly, but through the
|
|
9697
|
+
* `getAuthenticatedUserAndSigners` method.
|
|
9698
|
+
* @see getAuthenticatedUserAndSigners
|
|
9699
|
+
*/
|
|
9700
|
+
signers;
|
|
9701
|
+
signerInitialisationError;
|
|
9702
|
+
constructor({ authManager, immutableXClient, confirmationScreen, config, passportEventEmitter, magicAdapter, }) {
|
|
9662
9703
|
this.authManager = authManager;
|
|
9663
|
-
this.starkSigner = starkSigner;
|
|
9664
9704
|
this.immutableXClient = immutableXClient;
|
|
9665
9705
|
this.guardianClient = new GuardianClient({
|
|
9666
9706
|
confirmationScreen,
|
|
9667
9707
|
config,
|
|
9668
9708
|
});
|
|
9709
|
+
this.magicAdapter = magicAdapter;
|
|
9710
|
+
this.initialiseSigners();
|
|
9669
9711
|
passportEventEmitter.on(PassportEvents.LOGGED_OUT, this.handleLogout);
|
|
9670
9712
|
}
|
|
9671
9713
|
handleLogout = () => {
|
|
9672
|
-
this.
|
|
9714
|
+
this.signers = undefined;
|
|
9673
9715
|
};
|
|
9674
|
-
|
|
9716
|
+
/**
|
|
9717
|
+
* This method is called by the constructor and asynchronously initialises the signers.
|
|
9718
|
+
* The signers are stored in a promise so that they can be retrieved by the provider
|
|
9719
|
+
* when needed.
|
|
9720
|
+
*
|
|
9721
|
+
* If an error is thrown during initialisation, it is stored in the `signerInitialisationError`,
|
|
9722
|
+
* so that it doesn't result in an unhandled promise rejection.
|
|
9723
|
+
*
|
|
9724
|
+
* This error is thrown when the signers are requested through:
|
|
9725
|
+
* @see getAuthenticatedUserAndSigners
|
|
9726
|
+
*
|
|
9727
|
+
*/
|
|
9728
|
+
async initialiseSigners() {
|
|
9729
|
+
const generateSigners = async () => {
|
|
9730
|
+
const user = await this.authManager.getUser();
|
|
9731
|
+
// The user will be present because the factory validates it
|
|
9732
|
+
const magicRpcProvider = await this.magicAdapter.login(user.idToken);
|
|
9733
|
+
const web3Provider = new providers.Web3Provider(magicRpcProvider);
|
|
9734
|
+
const ethSigner = web3Provider.getSigner();
|
|
9735
|
+
const starkSigner = await getStarkSigner(ethSigner);
|
|
9736
|
+
return { ethSigner, starkSigner };
|
|
9737
|
+
};
|
|
9738
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
9739
|
+
this.signers = new Promise(async (resolve) => {
|
|
9740
|
+
try {
|
|
9741
|
+
resolve(await generateSigners());
|
|
9742
|
+
}
|
|
9743
|
+
catch (err) {
|
|
9744
|
+
// Capture and store the initialization error
|
|
9745
|
+
this.signerInitialisationError = err;
|
|
9746
|
+
resolve(undefined);
|
|
9747
|
+
}
|
|
9748
|
+
});
|
|
9749
|
+
}
|
|
9750
|
+
async getAuthenticatedUserAndSigners() {
|
|
9675
9751
|
const user = await this.authManager.getUser();
|
|
9676
|
-
if (!user || this.
|
|
9752
|
+
if (!user || !this.signers) {
|
|
9677
9753
|
throw new PassportError('User has been logged out', PassportErrorType.NOT_LOGGED_IN_ERROR);
|
|
9678
9754
|
}
|
|
9755
|
+
const signers = await this.signers;
|
|
9756
|
+
// Throw the stored error if the signers failed to initialise
|
|
9757
|
+
if (typeof signers === 'undefined') {
|
|
9758
|
+
if (typeof this.signerInitialisationError !== 'undefined') {
|
|
9759
|
+
throw this.signerInitialisationError;
|
|
9760
|
+
}
|
|
9761
|
+
throw new Error('Signers failed to initialise');
|
|
9762
|
+
}
|
|
9763
|
+
return { user, ...signers };
|
|
9764
|
+
}
|
|
9765
|
+
async getRegisteredImxUserAndSigners() {
|
|
9766
|
+
const { user, starkSigner, ethSigner } = await this.getAuthenticatedUserAndSigners();
|
|
9679
9767
|
const isUserImx = (oidcUser) => oidcUser?.imx !== undefined;
|
|
9680
9768
|
if (!isUserImx(user)) {
|
|
9681
9769
|
throw new PassportError('User has not been registered with StarkEx', PassportErrorType.USER_NOT_REGISTERED_ERROR);
|
|
9682
9770
|
}
|
|
9683
|
-
return { user, starkSigner
|
|
9771
|
+
return { user, starkSigner, ethSigner };
|
|
9684
9772
|
}
|
|
9685
9773
|
async transfer(request) {
|
|
9686
|
-
const { user, starkSigner } = await this.
|
|
9774
|
+
const { user, starkSigner } = await this.getRegisteredImxUserAndSigners();
|
|
9687
9775
|
return transfer$1({
|
|
9688
9776
|
request,
|
|
9689
9777
|
user,
|
|
@@ -9692,23 +9780,21 @@ class PassportImxProvider {
|
|
|
9692
9780
|
guardianClient: this.guardianClient,
|
|
9693
9781
|
});
|
|
9694
9782
|
}
|
|
9695
|
-
|
|
9696
|
-
|
|
9697
|
-
|
|
9698
|
-
throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
9783
|
+
async registerOffchain() {
|
|
9784
|
+
const { user, ethSigner, starkSigner } = await this.getAuthenticatedUserAndSigners();
|
|
9785
|
+
return await registerOffchain$1(ethSigner, starkSigner, user, this.authManager, this.immutableXClient.usersApi);
|
|
9699
9786
|
}
|
|
9700
|
-
|
|
9701
|
-
|
|
9702
|
-
|
|
9703
|
-
throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
9787
|
+
async isRegisteredOffchain() {
|
|
9788
|
+
const { user } = await this.getAuthenticatedUserAndSigners();
|
|
9789
|
+
return !!user.imx;
|
|
9704
9790
|
}
|
|
9705
9791
|
// TODO: Remove once implemented
|
|
9706
|
-
// eslint-disable-next-line class-methods-use-this
|
|
9792
|
+
// eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars
|
|
9707
9793
|
isRegisteredOnchain() {
|
|
9708
9794
|
throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
9709
9795
|
}
|
|
9710
9796
|
async createOrder(request) {
|
|
9711
|
-
const { user, starkSigner } = await this.
|
|
9797
|
+
const { user, starkSigner } = await this.getRegisteredImxUserAndSigners();
|
|
9712
9798
|
return createOrder$1({
|
|
9713
9799
|
request,
|
|
9714
9800
|
user,
|
|
@@ -9718,7 +9804,7 @@ class PassportImxProvider {
|
|
|
9718
9804
|
});
|
|
9719
9805
|
}
|
|
9720
9806
|
async cancelOrder(request) {
|
|
9721
|
-
const { user, starkSigner } = await this.
|
|
9807
|
+
const { user, starkSigner } = await this.getRegisteredImxUserAndSigners();
|
|
9722
9808
|
return cancelOrder$1({
|
|
9723
9809
|
request,
|
|
9724
9810
|
user,
|
|
@@ -9728,7 +9814,7 @@ class PassportImxProvider {
|
|
|
9728
9814
|
});
|
|
9729
9815
|
}
|
|
9730
9816
|
async createTrade(request) {
|
|
9731
|
-
const { user, starkSigner } = await this.
|
|
9817
|
+
const { user, starkSigner } = await this.getRegisteredImxUserAndSigners();
|
|
9732
9818
|
return createTrade$1({
|
|
9733
9819
|
request,
|
|
9734
9820
|
user,
|
|
@@ -9738,7 +9824,7 @@ class PassportImxProvider {
|
|
|
9738
9824
|
});
|
|
9739
9825
|
}
|
|
9740
9826
|
async batchNftTransfer(request) {
|
|
9741
|
-
const { user, starkSigner } = await this.
|
|
9827
|
+
const { user, starkSigner } = await this.getRegisteredImxUserAndSigners();
|
|
9742
9828
|
return batchNftTransfer({
|
|
9743
9829
|
request,
|
|
9744
9830
|
user,
|
|
@@ -9748,7 +9834,7 @@ class PassportImxProvider {
|
|
|
9748
9834
|
});
|
|
9749
9835
|
}
|
|
9750
9836
|
async exchangeTransfer(request) {
|
|
9751
|
-
const { user, starkSigner } = await this.
|
|
9837
|
+
const { user, starkSigner } = await this.getRegisteredImxUserAndSigners();
|
|
9752
9838
|
return exchangeTransfer$1({
|
|
9753
9839
|
request,
|
|
9754
9840
|
user,
|
|
@@ -9776,7 +9862,7 @@ class PassportImxProvider {
|
|
|
9776
9862
|
throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
9777
9863
|
}
|
|
9778
9864
|
async getAddress() {
|
|
9779
|
-
const { user } = await this.
|
|
9865
|
+
const { user } = await this.getRegisteredImxUserAndSigners();
|
|
9780
9866
|
return Promise.resolve(user.imx.ethAddress);
|
|
9781
9867
|
}
|
|
9782
9868
|
}
|
|
@@ -9836,49 +9922,15 @@ class PassportImxProviderFactory {
|
|
|
9836
9922
|
if (!user.idToken) {
|
|
9837
9923
|
throw new PassportError('Failed to initialise', PassportErrorType.WALLET_CONNECTION_ERROR);
|
|
9838
9924
|
}
|
|
9839
|
-
const magicRpcProvider = await this.magicAdapter.login(user.idToken);
|
|
9840
|
-
const web3Provider = new providers.Web3Provider(magicRpcProvider);
|
|
9841
|
-
const ethSigner = web3Provider.getSigner();
|
|
9842
|
-
const starkSigner = await getStarkSigner(ethSigner);
|
|
9843
|
-
if (!user.imx?.ethAddress) {
|
|
9844
|
-
await this.registerStarkEx(ethSigner, starkSigner, user.accessToken);
|
|
9845
|
-
return new PassportImxProvider({
|
|
9846
|
-
authManager: this.authManager,
|
|
9847
|
-
starkSigner,
|
|
9848
|
-
immutableXClient: this.immutableXClient,
|
|
9849
|
-
confirmationScreen: this.confirmationScreen,
|
|
9850
|
-
config: this.config,
|
|
9851
|
-
passportEventEmitter: this.passportEventEmitter,
|
|
9852
|
-
});
|
|
9853
|
-
}
|
|
9854
9925
|
return new PassportImxProvider({
|
|
9926
|
+
config: this.config,
|
|
9855
9927
|
authManager: this.authManager,
|
|
9856
|
-
starkSigner,
|
|
9857
9928
|
immutableXClient: this.immutableXClient,
|
|
9858
9929
|
confirmationScreen: this.confirmationScreen,
|
|
9859
|
-
config: this.config,
|
|
9860
9930
|
passportEventEmitter: this.passportEventEmitter,
|
|
9931
|
+
magicAdapter: this.magicAdapter,
|
|
9861
9932
|
});
|
|
9862
9933
|
}
|
|
9863
|
-
async registerStarkEx(userAdminKeySigner, starkSigner, jwt) {
|
|
9864
|
-
return withPassportError(async () => {
|
|
9865
|
-
await registerPassport({
|
|
9866
|
-
ethSigner: userAdminKeySigner,
|
|
9867
|
-
starkSigner,
|
|
9868
|
-
usersApi: this.immutableXClient.usersApi,
|
|
9869
|
-
}, jwt);
|
|
9870
|
-
// User metadata is updated asynchronously. Poll userinfo endpoint until it is updated.
|
|
9871
|
-
const updatedUser = await retryWithDelay(async () => {
|
|
9872
|
-
const user = await this.authManager.loginSilent({ forceRefresh: true }); // force refresh to get updated user info
|
|
9873
|
-
const metadataExists = !!user?.imx;
|
|
9874
|
-
if (metadataExists) {
|
|
9875
|
-
return user;
|
|
9876
|
-
}
|
|
9877
|
-
return Promise.reject(new Error('user wallet addresses not exist'));
|
|
9878
|
-
});
|
|
9879
|
-
return updatedUser;
|
|
9880
|
-
}, PassportErrorType.REFRESH_TOKEN_ERROR);
|
|
9881
|
-
}
|
|
9882
9934
|
}
|
|
9883
9935
|
|
|
9884
9936
|
const validateConfiguration = (configuration, requiredKeys, prefix) => {
|
|
@@ -33670,7 +33722,7 @@ var $045213b18e9f1f94$export$75be0f6af9650f2c;
|
|
|
33670
33722
|
})($045213b18e9f1f94$export$75be0f6af9650f2c || ($045213b18e9f1f94$export$75be0f6af9650f2c = {}));
|
|
33671
33723
|
|
|
33672
33724
|
|
|
33673
|
-
const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.
|
|
33725
|
+
const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.29.0";
|
|
33674
33726
|
const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
|
|
33675
33727
|
const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
|
|
33676
33728
|
|
package/dist/index.d.ts
CHANGED
|
@@ -8,16 +8,28 @@ declare class ImmutableConfiguration {
|
|
|
8
8
|
readonly environment: Environment;
|
|
9
9
|
readonly rateLimitingKey?: string;
|
|
10
10
|
readonly apiKey?: string;
|
|
11
|
-
readonly
|
|
11
|
+
readonly publishableKey?: string;
|
|
12
12
|
constructor(options: {
|
|
13
13
|
environment: Environment;
|
|
14
|
-
rateLimitingKey?: string;
|
|
15
|
-
apiKey?: string;
|
|
16
|
-
clientAppId?: string;
|
|
17
14
|
});
|
|
18
15
|
}
|
|
16
|
+
declare const addApiKeyToAxiosHeader: (apiKey: string) => void;
|
|
17
|
+
declare const addPublishableKeyToAxiosHeader: (publishableKey: string) => void;
|
|
18
|
+
declare const addRateLimitingKeyToAxiosHeader: (rateLimitingKey: string) => void;
|
|
19
|
+
type ImmutableConfigurationWithRequireableFields<T> = ImmutableConfiguration & (T extends {
|
|
20
|
+
apiKey: 'required';
|
|
21
|
+
} ? Required<{
|
|
22
|
+
apiKey: string;
|
|
23
|
+
}> : {}) & (T extends {
|
|
24
|
+
publishableKey: 'required';
|
|
25
|
+
} ? Required<{
|
|
26
|
+
publishableKey: string;
|
|
27
|
+
}> : {});
|
|
28
|
+
type ImmutableConfigurationWithOmitableFields<T> = (T extends {
|
|
29
|
+
apiKey: 'omit';
|
|
30
|
+
} ? Omit<ImmutableConfigurationWithRequireableFields<T>, 'apiKey'> : ImmutableConfigurationWithRequireableFields<T>);
|
|
19
31
|
interface ModuleConfiguration<T> {
|
|
20
|
-
baseConfig:
|
|
32
|
+
baseConfig: ImmutableConfigurationWithOmitableFields<T>;
|
|
21
33
|
overrides?: T;
|
|
22
34
|
}
|
|
23
35
|
|
|
@@ -26,11 +38,17 @@ declare const config_d_Environment: typeof Environment;
|
|
|
26
38
|
type config_d_ImmutableConfiguration = ImmutableConfiguration;
|
|
27
39
|
declare const config_d_ImmutableConfiguration: typeof ImmutableConfiguration;
|
|
28
40
|
type config_d_ModuleConfiguration<T> = ModuleConfiguration<T>;
|
|
41
|
+
declare const config_d_addApiKeyToAxiosHeader: typeof addApiKeyToAxiosHeader;
|
|
42
|
+
declare const config_d_addPublishableKeyToAxiosHeader: typeof addPublishableKeyToAxiosHeader;
|
|
43
|
+
declare const config_d_addRateLimitingKeyToAxiosHeader: typeof addRateLimitingKeyToAxiosHeader;
|
|
29
44
|
declare namespace config_d {
|
|
30
45
|
export {
|
|
31
46
|
config_d_Environment as Environment,
|
|
32
47
|
config_d_ImmutableConfiguration as ImmutableConfiguration,
|
|
33
48
|
config_d_ModuleConfiguration as ModuleConfiguration,
|
|
49
|
+
config_d_addApiKeyToAxiosHeader as addApiKeyToAxiosHeader,
|
|
50
|
+
config_d_addPublishableKeyToAxiosHeader as addPublishableKeyToAxiosHeader,
|
|
51
|
+
config_d_addRateLimitingKeyToAxiosHeader as addRateLimitingKeyToAxiosHeader,
|
|
34
52
|
};
|
|
35
53
|
}
|
|
36
54
|
|