@imtbl/sdk 0.28.10 → 0.29.0-alpha.1
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 +4 -4
- package/dist/browser/checkout/sdk.js +35 -0
- package/dist/browser/checkout/widgets.js +890 -0
- package/dist/checkout_sdk.d.ts +1308 -371
- package/dist/checkout_sdk.js +2896 -2421
- 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 +12 -21
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +3098 -3010
- package/dist/index.d.ts +1563 -15565
- package/dist/index.js +3101 -3012
- package/dist/orderbook.d.ts +14 -5
- package/dist/passport.d.ts +14 -5
- package/dist/passport.js +146 -98
- package/dist/provider.d.ts +14 -5
- package/package.json +17 -6
- package/dist/browser/checkout.js +0 -2
- package/dist/checkout_widgets.d.ts +0 -25605
- package/dist/checkout_widgets.js +0 -450
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
|
|
package/dist/passport.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, ethers } from 'ethers';
|
|
9
10
|
import BN 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';
|
|
@@ -719,7 +719,7 @@ const CollectionsApiAxiosParamCreator = function (configuration) {
|
|
|
719
719
|
const localVarHeaderParameter = {};
|
|
720
720
|
const localVarQueryParameter = {};
|
|
721
721
|
// authentication ImmutableApiKey required
|
|
722
|
-
await setApiKeyToObject(localVarHeaderParameter, "x-immutable-api-
|
|
722
|
+
await setApiKeyToObject(localVarHeaderParameter, "x-immutable-api-key", configuration);
|
|
723
723
|
localVarHeaderParameter['Content-Type'] = 'application/json';
|
|
724
724
|
setSearchParams$1(localVarUrlObj, localVarQueryParameter);
|
|
725
725
|
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
@@ -2072,7 +2072,7 @@ class MultiRollupApiClients {
|
|
|
2072
2072
|
}
|
|
2073
2073
|
|
|
2074
2074
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
2075
|
-
const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.
|
|
2075
|
+
const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.29.0-alpha.1' };
|
|
2076
2076
|
const createConfig = ({ basePath, headers, }) => {
|
|
2077
2077
|
if (!basePath.trim()) {
|
|
2078
2078
|
throw Error('basePath can not be empty');
|
|
@@ -2128,7 +2128,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
2128
2128
|
chainID,
|
|
2129
2129
|
coreContractAddress,
|
|
2130
2130
|
registrationContractAddress,
|
|
2131
|
-
sdkVersion: 'ts-immutable-sdk-0.
|
|
2131
|
+
sdkVersion: 'ts-immutable-sdk-0.29.0-alpha.1',
|
|
2132
2132
|
});
|
|
2133
2133
|
/**
|
|
2134
2134
|
* Sets `sdkVersion` at the time of build
|
|
@@ -6766,9 +6766,9 @@ class AuthManager {
|
|
|
6766
6766
|
};
|
|
6767
6767
|
if (passport?.imx_eth_address) {
|
|
6768
6768
|
user.imx = {
|
|
6769
|
-
ethAddress: passport
|
|
6770
|
-
starkAddress: passport
|
|
6771
|
-
userAdminAddress: passport
|
|
6769
|
+
ethAddress: passport.imx_eth_address,
|
|
6770
|
+
starkAddress: passport.imx_stark_address,
|
|
6771
|
+
userAdminAddress: passport.imx_user_admin_address,
|
|
6772
6772
|
};
|
|
6773
6773
|
}
|
|
6774
6774
|
if (passport?.zkevm_eth_address) {
|
|
@@ -6791,11 +6791,11 @@ class AuthManager {
|
|
|
6791
6791
|
nickname: idTokenPayload.nickname,
|
|
6792
6792
|
},
|
|
6793
6793
|
};
|
|
6794
|
-
if (idTokenPayload?.passport
|
|
6794
|
+
if (idTokenPayload?.passport.imx_eth_address) {
|
|
6795
6795
|
user.imx = {
|
|
6796
|
-
ethAddress: idTokenPayload
|
|
6797
|
-
starkAddress: idTokenPayload
|
|
6798
|
-
userAdminAddress: idTokenPayload
|
|
6796
|
+
ethAddress: idTokenPayload.passport.imx_eth_address,
|
|
6797
|
+
starkAddress: idTokenPayload.passport.imx_stark_address,
|
|
6798
|
+
userAdminAddress: idTokenPayload.passport.imx_user_admin_address,
|
|
6799
6799
|
};
|
|
6800
6800
|
}
|
|
6801
6801
|
if (idTokenPayload?.passport?.zkevm_eth_address) {
|
|
@@ -7056,7 +7056,7 @@ class AuthManager {
|
|
|
7056
7056
|
}
|
|
7057
7057
|
}
|
|
7058
7058
|
|
|
7059
|
-
const lazyLoad = (promiseToAwait, initialiseFunction) =>
|
|
7059
|
+
const lazyLoad = (promiseToAwait, initialiseFunction) => promiseToAwait().then(initialiseFunction);
|
|
7060
7060
|
const lazyDocumentReady = (initialiseFunction) => {
|
|
7061
7061
|
const documentReadyPromise = () => new Promise((resolve) => {
|
|
7062
7062
|
if (window.document.readyState === 'complete') {
|
|
@@ -7470,33 +7470,31 @@ async function cancelOrder({ user, starkSigner, request, ordersApi, guardianClie
|
|
|
7470
7470
|
}
|
|
7471
7471
|
|
|
7472
7472
|
async function registerPassport({ ethSigner, starkSigner, usersApi }, authorization) {
|
|
7473
|
-
|
|
7474
|
-
|
|
7475
|
-
|
|
7476
|
-
|
|
7477
|
-
|
|
7478
|
-
|
|
7479
|
-
|
|
7480
|
-
|
|
7481
|
-
|
|
7482
|
-
|
|
7483
|
-
|
|
7484
|
-
|
|
7485
|
-
|
|
7486
|
-
|
|
7487
|
-
|
|
7488
|
-
|
|
7489
|
-
|
|
7490
|
-
|
|
7491
|
-
|
|
7492
|
-
|
|
7493
|
-
|
|
7494
|
-
|
|
7495
|
-
|
|
7496
|
-
|
|
7497
|
-
|
|
7498
|
-
return response.statusText;
|
|
7499
|
-
}, PassportErrorType.USER_REGISTRATION_ERROR);
|
|
7473
|
+
const [userAddress, starkPublicKey] = await Promise.all([
|
|
7474
|
+
ethSigner.getAddress(),
|
|
7475
|
+
starkSigner.getAddress(),
|
|
7476
|
+
]);
|
|
7477
|
+
const signableResult = await usersApi.getSignableRegistrationOffchain({
|
|
7478
|
+
getSignableRegistrationRequest: {
|
|
7479
|
+
ether_key: userAddress,
|
|
7480
|
+
stark_key: starkPublicKey,
|
|
7481
|
+
},
|
|
7482
|
+
});
|
|
7483
|
+
const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
|
|
7484
|
+
const [ethSignature, starkSignature] = await Promise.all([
|
|
7485
|
+
signRaw(signableMessage, ethSigner),
|
|
7486
|
+
starkSigner.signMessage(payloadHash),
|
|
7487
|
+
]);
|
|
7488
|
+
const response = await usersApi.registerPassportUser({
|
|
7489
|
+
authorization: `Bearer ${authorization}`,
|
|
7490
|
+
registerPassportUserRequest: {
|
|
7491
|
+
eth_signature: ethSignature,
|
|
7492
|
+
ether_key: userAddress,
|
|
7493
|
+
stark_signature: starkSignature,
|
|
7494
|
+
stark_key: starkPublicKey,
|
|
7495
|
+
},
|
|
7496
|
+
});
|
|
7497
|
+
return response.data;
|
|
7500
7498
|
}
|
|
7501
7499
|
|
|
7502
7500
|
async function createTrade({ request, tradesApi, user, starkSigner, guardianClient, }) {
|
|
@@ -7642,37 +7640,123 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, guar
|
|
|
7642
7640
|
}), PassportErrorType.TRANSFER_ERROR);
|
|
7643
7641
|
}
|
|
7644
7642
|
|
|
7643
|
+
async function forceUserRefresh(authManager) {
|
|
7644
|
+
// User metadata is updated asynchronously. Poll userinfo endpoint until it is updated.
|
|
7645
|
+
await retryWithDelay(async () => {
|
|
7646
|
+
const user = await authManager.loginSilent({ forceRefresh: true }); // force refresh to get updated user info
|
|
7647
|
+
if (user?.imx)
|
|
7648
|
+
return user;
|
|
7649
|
+
return Promise.reject(new Error('user wallet addresses not exist'));
|
|
7650
|
+
});
|
|
7651
|
+
}
|
|
7652
|
+
async function registerOffchain(userAdminKeySigner, starkSigner, unregisteredUser, authManager, usersApi) {
|
|
7653
|
+
return withPassportError(async () => {
|
|
7654
|
+
try {
|
|
7655
|
+
const response = await registerPassport({
|
|
7656
|
+
ethSigner: userAdminKeySigner,
|
|
7657
|
+
starkSigner,
|
|
7658
|
+
usersApi,
|
|
7659
|
+
}, unregisteredUser.accessToken);
|
|
7660
|
+
await forceUserRefresh(authManager);
|
|
7661
|
+
return response;
|
|
7662
|
+
}
|
|
7663
|
+
catch (err) {
|
|
7664
|
+
if (globalAxios$1.isAxiosError(err) && err.status === 409) {
|
|
7665
|
+
// The user already registered, but the user token is not updated yet.
|
|
7666
|
+
await forceUserRefresh(authManager);
|
|
7667
|
+
return { tx_hash: '' };
|
|
7668
|
+
}
|
|
7669
|
+
throw err;
|
|
7670
|
+
}
|
|
7671
|
+
}, PassportErrorType.USER_REGISTRATION_ERROR);
|
|
7672
|
+
}
|
|
7673
|
+
|
|
7645
7674
|
class PassportImxProvider {
|
|
7646
7675
|
authManager;
|
|
7647
|
-
starkSigner;
|
|
7648
7676
|
immutableXClient;
|
|
7649
7677
|
guardianClient;
|
|
7650
|
-
|
|
7678
|
+
magicAdapter;
|
|
7679
|
+
/**
|
|
7680
|
+
* This property is set during initialisation and stores the signers in a promise.
|
|
7681
|
+
* This property is not meant to be accessed directly, but through the
|
|
7682
|
+
* `getAuthenticatedUserAndSigners` method.
|
|
7683
|
+
* @see getAuthenticatedUserAndSigners
|
|
7684
|
+
*/
|
|
7685
|
+
signers;
|
|
7686
|
+
signerInitialisationError;
|
|
7687
|
+
constructor({ authManager, immutableXClient, confirmationScreen, config, passportEventEmitter, magicAdapter, }) {
|
|
7651
7688
|
this.authManager = authManager;
|
|
7652
|
-
this.starkSigner = starkSigner;
|
|
7653
7689
|
this.immutableXClient = immutableXClient;
|
|
7654
7690
|
this.guardianClient = new GuardianClient({
|
|
7655
7691
|
confirmationScreen,
|
|
7656
7692
|
config,
|
|
7657
7693
|
});
|
|
7694
|
+
this.magicAdapter = magicAdapter;
|
|
7695
|
+
this.initialiseSigners();
|
|
7658
7696
|
passportEventEmitter.on(PassportEvents.LOGGED_OUT, this.handleLogout);
|
|
7659
7697
|
}
|
|
7660
7698
|
handleLogout = () => {
|
|
7661
|
-
this.
|
|
7699
|
+
this.signers = undefined;
|
|
7662
7700
|
};
|
|
7663
|
-
|
|
7701
|
+
/**
|
|
7702
|
+
* This method is called by the constructor and asynchronously initialises the signers.
|
|
7703
|
+
* The signers are stored in a promise so that they can be retrieved by the provider
|
|
7704
|
+
* when needed.
|
|
7705
|
+
*
|
|
7706
|
+
* If an error is thrown during initialisation, it is stored in the `signerInitialisationError`,
|
|
7707
|
+
* so that it doesn't result in an unhandled promise rejection.
|
|
7708
|
+
*
|
|
7709
|
+
* This error is thrown when the signers are requested through:
|
|
7710
|
+
* @see getAuthenticatedUserAndSigners
|
|
7711
|
+
*
|
|
7712
|
+
*/
|
|
7713
|
+
async initialiseSigners() {
|
|
7714
|
+
const generateSigners = async () => {
|
|
7715
|
+
const user = await this.authManager.getUser();
|
|
7716
|
+
// The user will be present because the factory validates it
|
|
7717
|
+
const magicRpcProvider = await this.magicAdapter.login(user.idToken);
|
|
7718
|
+
const web3Provider = new Web3Provider(magicRpcProvider);
|
|
7719
|
+
const ethSigner = web3Provider.getSigner();
|
|
7720
|
+
const starkSigner = await getStarkSigner(ethSigner);
|
|
7721
|
+
return { ethSigner, starkSigner };
|
|
7722
|
+
};
|
|
7723
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
7724
|
+
this.signers = new Promise(async (resolve) => {
|
|
7725
|
+
try {
|
|
7726
|
+
resolve(await generateSigners());
|
|
7727
|
+
}
|
|
7728
|
+
catch (err) {
|
|
7729
|
+
// Capture and store the initialization error
|
|
7730
|
+
this.signerInitialisationError = err;
|
|
7731
|
+
resolve(undefined);
|
|
7732
|
+
}
|
|
7733
|
+
});
|
|
7734
|
+
}
|
|
7735
|
+
async getAuthenticatedUserAndSigners() {
|
|
7664
7736
|
const user = await this.authManager.getUser();
|
|
7665
|
-
if (!user || this.
|
|
7737
|
+
if (!user || !this.signers) {
|
|
7666
7738
|
throw new PassportError('User has been logged out', PassportErrorType.NOT_LOGGED_IN_ERROR);
|
|
7667
7739
|
}
|
|
7740
|
+
const signers = await this.signers;
|
|
7741
|
+
// Throw the stored error if the signers failed to initialise
|
|
7742
|
+
if (typeof signers === 'undefined') {
|
|
7743
|
+
if (typeof this.signerInitialisationError !== 'undefined') {
|
|
7744
|
+
throw this.signerInitialisationError;
|
|
7745
|
+
}
|
|
7746
|
+
throw new Error('Signers failed to initialise');
|
|
7747
|
+
}
|
|
7748
|
+
return { user, ...signers };
|
|
7749
|
+
}
|
|
7750
|
+
async getRegisteredImxUserAndSigners() {
|
|
7751
|
+
const { user, starkSigner, ethSigner } = await this.getAuthenticatedUserAndSigners();
|
|
7668
7752
|
const isUserImx = (oidcUser) => oidcUser?.imx !== undefined;
|
|
7669
7753
|
if (!isUserImx(user)) {
|
|
7670
7754
|
throw new PassportError('User has not been registered with StarkEx', PassportErrorType.USER_NOT_REGISTERED_ERROR);
|
|
7671
7755
|
}
|
|
7672
|
-
return { user, starkSigner
|
|
7756
|
+
return { user, starkSigner, ethSigner };
|
|
7673
7757
|
}
|
|
7674
7758
|
async transfer(request) {
|
|
7675
|
-
const { user, starkSigner } = await this.
|
|
7759
|
+
const { user, starkSigner } = await this.getRegisteredImxUserAndSigners();
|
|
7676
7760
|
return transfer({
|
|
7677
7761
|
request,
|
|
7678
7762
|
user,
|
|
@@ -7681,23 +7765,21 @@ class PassportImxProvider {
|
|
|
7681
7765
|
guardianClient: this.guardianClient,
|
|
7682
7766
|
});
|
|
7683
7767
|
}
|
|
7684
|
-
|
|
7685
|
-
|
|
7686
|
-
|
|
7687
|
-
throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
7768
|
+
async registerOffchain() {
|
|
7769
|
+
const { user, ethSigner, starkSigner } = await this.getAuthenticatedUserAndSigners();
|
|
7770
|
+
return await registerOffchain(ethSigner, starkSigner, user, this.authManager, this.immutableXClient.usersApi);
|
|
7688
7771
|
}
|
|
7689
|
-
|
|
7690
|
-
|
|
7691
|
-
|
|
7692
|
-
throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
7772
|
+
async isRegisteredOffchain() {
|
|
7773
|
+
const { user } = await this.getAuthenticatedUserAndSigners();
|
|
7774
|
+
return !!user.imx;
|
|
7693
7775
|
}
|
|
7694
7776
|
// TODO: Remove once implemented
|
|
7695
|
-
// eslint-disable-next-line class-methods-use-this
|
|
7777
|
+
// eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars
|
|
7696
7778
|
isRegisteredOnchain() {
|
|
7697
7779
|
throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
7698
7780
|
}
|
|
7699
7781
|
async createOrder(request) {
|
|
7700
|
-
const { user, starkSigner } = await this.
|
|
7782
|
+
const { user, starkSigner } = await this.getRegisteredImxUserAndSigners();
|
|
7701
7783
|
return createOrder({
|
|
7702
7784
|
request,
|
|
7703
7785
|
user,
|
|
@@ -7707,7 +7789,7 @@ class PassportImxProvider {
|
|
|
7707
7789
|
});
|
|
7708
7790
|
}
|
|
7709
7791
|
async cancelOrder(request) {
|
|
7710
|
-
const { user, starkSigner } = await this.
|
|
7792
|
+
const { user, starkSigner } = await this.getRegisteredImxUserAndSigners();
|
|
7711
7793
|
return cancelOrder({
|
|
7712
7794
|
request,
|
|
7713
7795
|
user,
|
|
@@ -7717,7 +7799,7 @@ class PassportImxProvider {
|
|
|
7717
7799
|
});
|
|
7718
7800
|
}
|
|
7719
7801
|
async createTrade(request) {
|
|
7720
|
-
const { user, starkSigner } = await this.
|
|
7802
|
+
const { user, starkSigner } = await this.getRegisteredImxUserAndSigners();
|
|
7721
7803
|
return createTrade({
|
|
7722
7804
|
request,
|
|
7723
7805
|
user,
|
|
@@ -7727,7 +7809,7 @@ class PassportImxProvider {
|
|
|
7727
7809
|
});
|
|
7728
7810
|
}
|
|
7729
7811
|
async batchNftTransfer(request) {
|
|
7730
|
-
const { user, starkSigner } = await this.
|
|
7812
|
+
const { user, starkSigner } = await this.getRegisteredImxUserAndSigners();
|
|
7731
7813
|
return batchNftTransfer({
|
|
7732
7814
|
request,
|
|
7733
7815
|
user,
|
|
@@ -7737,7 +7819,7 @@ class PassportImxProvider {
|
|
|
7737
7819
|
});
|
|
7738
7820
|
}
|
|
7739
7821
|
async exchangeTransfer(request) {
|
|
7740
|
-
const { user, starkSigner } = await this.
|
|
7822
|
+
const { user, starkSigner } = await this.getRegisteredImxUserAndSigners();
|
|
7741
7823
|
return exchangeTransfer({
|
|
7742
7824
|
request,
|
|
7743
7825
|
user,
|
|
@@ -7765,7 +7847,7 @@ class PassportImxProvider {
|
|
|
7765
7847
|
throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
|
|
7766
7848
|
}
|
|
7767
7849
|
async getAddress() {
|
|
7768
|
-
const { user } = await this.
|
|
7850
|
+
const { user } = await this.getRegisteredImxUserAndSigners();
|
|
7769
7851
|
return Promise.resolve(user.imx.ethAddress);
|
|
7770
7852
|
}
|
|
7771
7853
|
}
|
|
@@ -7825,49 +7907,15 @@ class PassportImxProviderFactory {
|
|
|
7825
7907
|
if (!user.idToken) {
|
|
7826
7908
|
throw new PassportError('Failed to initialise', PassportErrorType.WALLET_CONNECTION_ERROR);
|
|
7827
7909
|
}
|
|
7828
|
-
const magicRpcProvider = await this.magicAdapter.login(user.idToken);
|
|
7829
|
-
const web3Provider = new Web3Provider(magicRpcProvider);
|
|
7830
|
-
const ethSigner = web3Provider.getSigner();
|
|
7831
|
-
const starkSigner = await getStarkSigner(ethSigner);
|
|
7832
|
-
if (!user.imx?.ethAddress) {
|
|
7833
|
-
await this.registerStarkEx(ethSigner, starkSigner, user.accessToken);
|
|
7834
|
-
return new PassportImxProvider({
|
|
7835
|
-
authManager: this.authManager,
|
|
7836
|
-
starkSigner,
|
|
7837
|
-
immutableXClient: this.immutableXClient,
|
|
7838
|
-
confirmationScreen: this.confirmationScreen,
|
|
7839
|
-
config: this.config,
|
|
7840
|
-
passportEventEmitter: this.passportEventEmitter,
|
|
7841
|
-
});
|
|
7842
|
-
}
|
|
7843
7910
|
return new PassportImxProvider({
|
|
7911
|
+
config: this.config,
|
|
7844
7912
|
authManager: this.authManager,
|
|
7845
|
-
starkSigner,
|
|
7846
7913
|
immutableXClient: this.immutableXClient,
|
|
7847
7914
|
confirmationScreen: this.confirmationScreen,
|
|
7848
|
-
config: this.config,
|
|
7849
7915
|
passportEventEmitter: this.passportEventEmitter,
|
|
7916
|
+
magicAdapter: this.magicAdapter,
|
|
7850
7917
|
});
|
|
7851
7918
|
}
|
|
7852
|
-
async registerStarkEx(userAdminKeySigner, starkSigner, jwt) {
|
|
7853
|
-
return withPassportError(async () => {
|
|
7854
|
-
await registerPassport({
|
|
7855
|
-
ethSigner: userAdminKeySigner,
|
|
7856
|
-
starkSigner,
|
|
7857
|
-
usersApi: this.immutableXClient.usersApi,
|
|
7858
|
-
}, jwt);
|
|
7859
|
-
// User metadata is updated asynchronously. Poll userinfo endpoint until it is updated.
|
|
7860
|
-
const updatedUser = await retryWithDelay(async () => {
|
|
7861
|
-
const user = await this.authManager.loginSilent({ forceRefresh: true }); // force refresh to get updated user info
|
|
7862
|
-
const metadataExists = !!user?.imx;
|
|
7863
|
-
if (metadataExists) {
|
|
7864
|
-
return user;
|
|
7865
|
-
}
|
|
7866
|
-
return Promise.reject(new Error('user wallet addresses not exist'));
|
|
7867
|
-
});
|
|
7868
|
-
return updatedUser;
|
|
7869
|
-
}, PassportErrorType.REFRESH_TOKEN_ERROR);
|
|
7870
|
-
}
|
|
7871
7919
|
}
|
|
7872
7920
|
|
|
7873
7921
|
const validateConfiguration = (configuration, requiredKeys, prefix) => {
|
package/dist/provider.d.ts
CHANGED
|
@@ -917,16 +917,25 @@ declare class ImmutableConfiguration {
|
|
|
917
917
|
readonly environment: Environment;
|
|
918
918
|
readonly rateLimitingKey?: string;
|
|
919
919
|
readonly apiKey?: string;
|
|
920
|
-
readonly
|
|
920
|
+
readonly publishableKey?: string;
|
|
921
921
|
constructor(options: {
|
|
922
922
|
environment: Environment;
|
|
923
|
-
rateLimitingKey?: string;
|
|
924
|
-
apiKey?: string;
|
|
925
|
-
clientAppId?: string;
|
|
926
923
|
});
|
|
927
924
|
}
|
|
925
|
+
type ImmutableConfigurationWithRequireableFields<T> = ImmutableConfiguration & (T extends {
|
|
926
|
+
apiKey: 'required';
|
|
927
|
+
} ? Required<{
|
|
928
|
+
apiKey: string;
|
|
929
|
+
}> : {}) & (T extends {
|
|
930
|
+
publishableKey: 'required';
|
|
931
|
+
} ? Required<{
|
|
932
|
+
publishableKey: string;
|
|
933
|
+
}> : {});
|
|
934
|
+
type ImmutableConfigurationWithOmitableFields<T> = (T extends {
|
|
935
|
+
apiKey: 'omit';
|
|
936
|
+
} ? Omit<ImmutableConfigurationWithRequireableFields<T>, 'apiKey'> : ImmutableConfigurationWithRequireableFields<T>);
|
|
928
937
|
interface ModuleConfiguration<T> {
|
|
929
|
-
baseConfig:
|
|
938
|
+
baseConfig: ImmutableConfigurationWithOmitableFields<T>;
|
|
930
939
|
overrides?: T;
|
|
931
940
|
}
|
|
932
941
|
|
package/package.json
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imtbl/sdk",
|
|
3
3
|
"description": "Immutable Unified SDK",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.29.0-alpha.1",
|
|
5
5
|
"author": "Immutable",
|
|
6
6
|
"browser": "./dist/index.browser.js",
|
|
7
7
|
"bugs": "https://github.com/immutable/ts-immutable-sdk/issues",
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@0xsequence/abi": "^0.43.34",
|
|
10
10
|
"@0xsequence/config": "^0.43.34",
|
|
11
|
+
"@biom3/design-tokens": "0.2.4-beta",
|
|
12
|
+
"@biom3/react": "^0.10.12",
|
|
11
13
|
"@ethersproject/abi": "^5.7.0",
|
|
12
14
|
"@ethersproject/abstract-signer": "^5.7.0",
|
|
13
15
|
"@ethersproject/providers": "^5.7.2",
|
|
14
16
|
"@ethersproject/wallet": "^5.7.0",
|
|
15
17
|
"@imtbl/core-sdk": "^2.4.0",
|
|
18
|
+
"@imtbl/react-analytics": "0.2.1-alpha",
|
|
16
19
|
"@jest/globals": "^29.5.0",
|
|
17
20
|
"@magic-ext/oidc": "^4.2.0",
|
|
18
21
|
"@metamask/detect-provider": "^2.0.0",
|
|
@@ -20,13 +23,25 @@
|
|
|
20
23
|
"@uniswap/router-sdk": "^1.4.0",
|
|
21
24
|
"@uniswap/sdk-core": "^3.0.1",
|
|
22
25
|
"@uniswap/v3-sdk": "^3.9.0",
|
|
26
|
+
"assert": "^2.0.0",
|
|
23
27
|
"axios": "^1.3.5",
|
|
24
28
|
"bn.js": "^5.2.1",
|
|
29
|
+
"buffer": "^6.0.3",
|
|
30
|
+
"crypto-browserify": "^3.12.0",
|
|
25
31
|
"enc-utils": "^3.0.0",
|
|
26
32
|
"ethers": "^5.7.2",
|
|
33
|
+
"https-browserify": "^1.0.0",
|
|
27
34
|
"jwt-decode": "^3.1.2",
|
|
28
35
|
"magic-sdk": "^21.2.0",
|
|
29
|
-
"oidc-client-ts": "^2.2.1"
|
|
36
|
+
"oidc-client-ts": "^2.2.1",
|
|
37
|
+
"os-browserify": "^0.3.0",
|
|
38
|
+
"pako": "^2.1.0",
|
|
39
|
+
"react": "^18.2.0",
|
|
40
|
+
"react-dom": "^18.2.0",
|
|
41
|
+
"react-router-dom": "^6.11.0",
|
|
42
|
+
"stream-browserify": "^3.0.0",
|
|
43
|
+
"stream-http": "^3.2.0",
|
|
44
|
+
"url": "^0.11.0"
|
|
30
45
|
},
|
|
31
46
|
"devDependencies": {
|
|
32
47
|
"@imtbl/blockchain-data": "0.0.0",
|
|
@@ -94,10 +109,6 @@
|
|
|
94
109
|
"./checkout_sdk": {
|
|
95
110
|
"types": "./dist/checkout_sdk.d.ts",
|
|
96
111
|
"import": "./dist/checkout_sdk.js"
|
|
97
|
-
},
|
|
98
|
-
"./checkout_widgets": {
|
|
99
|
-
"types": "./dist/checkout_widgets.d.ts",
|
|
100
|
-
"import": "./dist/checkout_widgets.js"
|
|
101
112
|
}
|
|
102
113
|
},
|
|
103
114
|
"files": [
|