@imtbl/sdk 1.7.3-alpha.1 → 1.7.3-alpha.2
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/blockchain_data.d.ts +288 -449
- package/dist/blockchain_data.js +2 -149
- package/dist/browser/checkout/BridgeWidget-85db50d2.js +1 -0
- package/dist/browser/checkout/OnRampWidget-58400404.js +1 -0
- package/dist/browser/checkout/SaleWidget-549f0f75.js +2 -0
- package/dist/browser/checkout/SpendingCapHero-24fed6d2.js +1 -0
- package/dist/browser/checkout/SwapWidget-9eecba27.js +1 -0
- package/dist/browser/checkout/TopUpView-26964a9e.js +1 -0
- package/dist/browser/checkout/WalletWidget-7e6fed9c.js +1 -0
- package/dist/browser/checkout/auto-track-da38e5a8.js +1 -0
- package/dist/browser/checkout/balance-310539bb.js +1 -0
- package/dist/browser/checkout/index-392bc434.js +1 -0
- package/dist/browser/checkout/index-3d847e0c.js +1 -0
- package/dist/browser/checkout/index-4e77760b.js +773 -0
- package/dist/browser/checkout/index-8184ffea.js +1 -0
- package/dist/browser/checkout/index-919a5df1.js +1 -0
- package/dist/browser/checkout/index-e6159023.js +1 -0
- package/dist/browser/checkout/index-eb42cd09.js +106 -0
- package/dist/browser/checkout/index.umd-c2e32802.js +1 -0
- package/dist/browser/checkout/is-plan-event-enabled-80f76ce6.js +1 -0
- package/dist/browser/checkout/retry-355e44f2.js +1 -0
- package/dist/browser/checkout/sdk.js +4 -4
- package/dist/browser/checkout/useTransakEvents-c6a83ea5.js +2 -0
- package/dist/browser/checkout/widgets-esm.js +1 -0
- package/dist/browser/checkout/widgets.js +50 -51
- package/dist/checkout.d.ts +3 -1
- package/dist/checkout.js +65 -179
- package/dist/config.js +1 -1
- package/dist/index.browser.js +7 -7
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +200 -290
- package/dist/index.d.ts +291 -450
- package/dist/index.js +200 -290
- package/dist/orderbook.js +1 -1
- package/dist/passport.js +136 -239
- package/dist/x.js +2 -2
- package/package.json +1 -1
package/dist/orderbook.js
CHANGED
|
@@ -131,7 +131,7 @@ const flattenProperties = (properties) => {
|
|
|
131
131
|
};
|
|
132
132
|
|
|
133
133
|
// WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
|
|
134
|
-
const SDK_VERSION = '1.7.3-alpha.
|
|
134
|
+
const SDK_VERSION = '1.7.3-alpha.2';
|
|
135
135
|
const getReferrer = () => {
|
|
136
136
|
if (isNode()) {
|
|
137
137
|
return '';
|
package/dist/passport.js
CHANGED
|
@@ -7465,85 +7465,6 @@ class NftOwnersApi extends BaseAPI$2 {
|
|
|
7465
7465
|
*/
|
|
7466
7466
|
const NftsApiAxiosParamCreator = function (configuration) {
|
|
7467
7467
|
return {
|
|
7468
|
-
/**
|
|
7469
|
-
* Create a mint request to mint a set of NFTs for a given collection
|
|
7470
|
-
* @summary Mint NFTs
|
|
7471
|
-
* @param {string} contractAddress The address of contract
|
|
7472
|
-
* @param {string} chainName The name of chain
|
|
7473
|
-
* @param {CreateMintRequestRequest} createMintRequestRequest the request body
|
|
7474
|
-
* @param {*} [options] Override http request option.
|
|
7475
|
-
* @throws {RequiredError}
|
|
7476
|
-
*/
|
|
7477
|
-
createMintRequest: async (contractAddress, chainName, createMintRequestRequest, options = {}) => {
|
|
7478
|
-
// verify required parameter 'contractAddress' is not null or undefined
|
|
7479
|
-
assertParamExists$2('createMintRequest', 'contractAddress', contractAddress);
|
|
7480
|
-
// verify required parameter 'chainName' is not null or undefined
|
|
7481
|
-
assertParamExists$2('createMintRequest', 'chainName', chainName);
|
|
7482
|
-
// verify required parameter 'createMintRequestRequest' is not null or undefined
|
|
7483
|
-
assertParamExists$2('createMintRequest', 'createMintRequestRequest', createMintRequestRequest);
|
|
7484
|
-
const localVarPath = `/v1/chains/{chain_name}/collections/{contract_address}/nfts/mint-requests`
|
|
7485
|
-
.replace(`{${"contract_address"}}`, encodeURIComponent(String(contractAddress)))
|
|
7486
|
-
.replace(`{${"chain_name"}}`, encodeURIComponent(String(chainName)));
|
|
7487
|
-
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
7488
|
-
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL$2);
|
|
7489
|
-
let baseOptions;
|
|
7490
|
-
if (configuration) {
|
|
7491
|
-
baseOptions = configuration.baseOptions;
|
|
7492
|
-
}
|
|
7493
|
-
const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options };
|
|
7494
|
-
const localVarHeaderParameter = {};
|
|
7495
|
-
const localVarQueryParameter = {};
|
|
7496
|
-
// authentication ImmutableApiKey required
|
|
7497
|
-
await setApiKeyToObject(localVarHeaderParameter, "x-immutable-api-key", configuration);
|
|
7498
|
-
localVarHeaderParameter['Content-Type'] = 'application/json';
|
|
7499
|
-
setSearchParams$2(localVarUrlObj, localVarQueryParameter);
|
|
7500
|
-
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
7501
|
-
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
7502
|
-
localVarRequestOptions.data = serializeDataIfNeeded$2(createMintRequestRequest, localVarRequestOptions, configuration);
|
|
7503
|
-
return {
|
|
7504
|
-
url: toPathString$2(localVarUrlObj),
|
|
7505
|
-
options: localVarRequestOptions,
|
|
7506
|
-
};
|
|
7507
|
-
},
|
|
7508
|
-
/**
|
|
7509
|
-
* Retrieve the status of a mint request identified by its reference_id
|
|
7510
|
-
* @summary Mint NFTs
|
|
7511
|
-
* @param {string} contractAddress The address of contract
|
|
7512
|
-
* @param {string} chainName The name of chain
|
|
7513
|
-
* @param {string} referenceId The ID of the mint request
|
|
7514
|
-
* @param {*} [options] Override http request option.
|
|
7515
|
-
* @throws {RequiredError}
|
|
7516
|
-
*/
|
|
7517
|
-
getMintRequest: async (contractAddress, chainName, referenceId, options = {}) => {
|
|
7518
|
-
// verify required parameter 'contractAddress' is not null or undefined
|
|
7519
|
-
assertParamExists$2('getMintRequest', 'contractAddress', contractAddress);
|
|
7520
|
-
// verify required parameter 'chainName' is not null or undefined
|
|
7521
|
-
assertParamExists$2('getMintRequest', 'chainName', chainName);
|
|
7522
|
-
// verify required parameter 'referenceId' is not null or undefined
|
|
7523
|
-
assertParamExists$2('getMintRequest', 'referenceId', referenceId);
|
|
7524
|
-
const localVarPath = `/v1/chains/{chain_name}/collections/{contract_address}/nfts/mint-requests/{reference_id}`
|
|
7525
|
-
.replace(`{${"contract_address"}}`, encodeURIComponent(String(contractAddress)))
|
|
7526
|
-
.replace(`{${"chain_name"}}`, encodeURIComponent(String(chainName)))
|
|
7527
|
-
.replace(`{${"reference_id"}}`, encodeURIComponent(String(referenceId)));
|
|
7528
|
-
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
7529
|
-
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL$2);
|
|
7530
|
-
let baseOptions;
|
|
7531
|
-
if (configuration) {
|
|
7532
|
-
baseOptions = configuration.baseOptions;
|
|
7533
|
-
}
|
|
7534
|
-
const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options };
|
|
7535
|
-
const localVarHeaderParameter = {};
|
|
7536
|
-
const localVarQueryParameter = {};
|
|
7537
|
-
// authentication ImmutableApiKey required
|
|
7538
|
-
await setApiKeyToObject(localVarHeaderParameter, "x-immutable-api-key", configuration);
|
|
7539
|
-
setSearchParams$2(localVarUrlObj, localVarQueryParameter);
|
|
7540
|
-
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
7541
|
-
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
7542
|
-
return {
|
|
7543
|
-
url: toPathString$2(localVarUrlObj),
|
|
7544
|
-
options: localVarRequestOptions,
|
|
7545
|
-
};
|
|
7546
|
-
},
|
|
7547
7468
|
/**
|
|
7548
7469
|
* Get NFT by token ID
|
|
7549
7470
|
* @summary Get NFT by token ID
|
|
@@ -7729,32 +7650,6 @@ const NftsApiAxiosParamCreator = function (configuration) {
|
|
|
7729
7650
|
const NftsApiFp = function (configuration) {
|
|
7730
7651
|
const localVarAxiosParamCreator = NftsApiAxiosParamCreator(configuration);
|
|
7731
7652
|
return {
|
|
7732
|
-
/**
|
|
7733
|
-
* Create a mint request to mint a set of NFTs for a given collection
|
|
7734
|
-
* @summary Mint NFTs
|
|
7735
|
-
* @param {string} contractAddress The address of contract
|
|
7736
|
-
* @param {string} chainName The name of chain
|
|
7737
|
-
* @param {CreateMintRequestRequest} createMintRequestRequest the request body
|
|
7738
|
-
* @param {*} [options] Override http request option.
|
|
7739
|
-
* @throws {RequiredError}
|
|
7740
|
-
*/
|
|
7741
|
-
async createMintRequest(contractAddress, chainName, createMintRequestRequest, options) {
|
|
7742
|
-
const localVarAxiosArgs = await localVarAxiosParamCreator.createMintRequest(contractAddress, chainName, createMintRequestRequest, options);
|
|
7743
|
-
return createRequestFunction$2(localVarAxiosArgs, globalAxios$1, BASE_PATH$2, configuration);
|
|
7744
|
-
},
|
|
7745
|
-
/**
|
|
7746
|
-
* Retrieve the status of a mint request identified by its reference_id
|
|
7747
|
-
* @summary Mint NFTs
|
|
7748
|
-
* @param {string} contractAddress The address of contract
|
|
7749
|
-
* @param {string} chainName The name of chain
|
|
7750
|
-
* @param {string} referenceId The ID of the mint request
|
|
7751
|
-
* @param {*} [options] Override http request option.
|
|
7752
|
-
* @throws {RequiredError}
|
|
7753
|
-
*/
|
|
7754
|
-
async getMintRequest(contractAddress, chainName, referenceId, options) {
|
|
7755
|
-
const localVarAxiosArgs = await localVarAxiosParamCreator.getMintRequest(contractAddress, chainName, referenceId, options);
|
|
7756
|
-
return createRequestFunction$2(localVarAxiosArgs, globalAxios$1, BASE_PATH$2, configuration);
|
|
7757
|
-
},
|
|
7758
7653
|
/**
|
|
7759
7654
|
* Get NFT by token ID
|
|
7760
7655
|
* @summary Get NFT by token ID
|
|
@@ -7822,28 +7717,6 @@ const NftsApiFp = function (configuration) {
|
|
|
7822
7717
|
* @extends {BaseAPI}
|
|
7823
7718
|
*/
|
|
7824
7719
|
class NftsApi extends BaseAPI$2 {
|
|
7825
|
-
/**
|
|
7826
|
-
* Create a mint request to mint a set of NFTs for a given collection
|
|
7827
|
-
* @summary Mint NFTs
|
|
7828
|
-
* @param {NftsApiCreateMintRequestRequest} requestParameters Request parameters.
|
|
7829
|
-
* @param {*} [options] Override http request option.
|
|
7830
|
-
* @throws {RequiredError}
|
|
7831
|
-
* @memberof NftsApi
|
|
7832
|
-
*/
|
|
7833
|
-
createMintRequest(requestParameters, options) {
|
|
7834
|
-
return NftsApiFp(this.configuration).createMintRequest(requestParameters.contractAddress, requestParameters.chainName, requestParameters.createMintRequestRequest, options).then((request) => request(this.axios, this.basePath));
|
|
7835
|
-
}
|
|
7836
|
-
/**
|
|
7837
|
-
* Retrieve the status of a mint request identified by its reference_id
|
|
7838
|
-
* @summary Mint NFTs
|
|
7839
|
-
* @param {NftsApiGetMintRequestRequest} requestParameters Request parameters.
|
|
7840
|
-
* @param {*} [options] Override http request option.
|
|
7841
|
-
* @throws {RequiredError}
|
|
7842
|
-
* @memberof NftsApi
|
|
7843
|
-
*/
|
|
7844
|
-
getMintRequest(requestParameters, options) {
|
|
7845
|
-
return NftsApiFp(this.configuration).getMintRequest(requestParameters.contractAddress, requestParameters.chainName, requestParameters.referenceId, options).then((request) => request(this.axios, this.basePath));
|
|
7846
|
-
}
|
|
7847
7720
|
/**
|
|
7848
7721
|
* Get NFT by token ID
|
|
7849
7722
|
* @summary Get NFT by token ID
|
|
@@ -9273,7 +9146,7 @@ class MultiRollupApiClients {
|
|
|
9273
9146
|
}
|
|
9274
9147
|
|
|
9275
9148
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
9276
|
-
const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.7.3-alpha.
|
|
9149
|
+
const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.7.3-alpha.2' };
|
|
9277
9150
|
const createConfig = ({ basePath, headers, }) => {
|
|
9278
9151
|
if (!basePath.trim()) {
|
|
9279
9152
|
throw Error('basePath can not be empty');
|
|
@@ -9452,7 +9325,7 @@ const flattenProperties = (properties) => {
|
|
|
9452
9325
|
};
|
|
9453
9326
|
|
|
9454
9327
|
// WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
|
|
9455
|
-
const SDK_VERSION = '1.7.3-alpha.
|
|
9328
|
+
const SDK_VERSION = '1.7.3-alpha.2';
|
|
9456
9329
|
const getReferrer = () => {
|
|
9457
9330
|
if (isNode()) {
|
|
9458
9331
|
return '';
|
|
@@ -9665,7 +9538,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
9665
9538
|
chainID,
|
|
9666
9539
|
coreContractAddress,
|
|
9667
9540
|
registrationContractAddress,
|
|
9668
|
-
sdkVersion: 'ts-immutable-sdk-1.7.3-alpha.
|
|
9541
|
+
sdkVersion: 'ts-immutable-sdk-1.7.3-alpha.2',
|
|
9669
9542
|
});
|
|
9670
9543
|
/**
|
|
9671
9544
|
* Sets `sdkVersion` at the time of build
|
|
@@ -14303,7 +14176,6 @@ const getAuthConfiguration = (config) => {
|
|
|
14303
14176
|
end_session_endpoint: endSessionEndpoint,
|
|
14304
14177
|
},
|
|
14305
14178
|
mergeClaims: true,
|
|
14306
|
-
loadUserInfo: true,
|
|
14307
14179
|
scope: oidcConfiguration.scope,
|
|
14308
14180
|
userStore,
|
|
14309
14181
|
};
|
|
@@ -14344,7 +14216,10 @@ class AuthManager {
|
|
|
14344
14216
|
this.logoutMode = config.oidcConfiguration.logoutMode || 'redirect';
|
|
14345
14217
|
}
|
|
14346
14218
|
static mapOidcUserToDomainModel = (oidcUser) => {
|
|
14347
|
-
|
|
14219
|
+
let passport;
|
|
14220
|
+
if (oidcUser.id_token) {
|
|
14221
|
+
passport = jwt_decode(oidcUser.id_token)?.passport;
|
|
14222
|
+
}
|
|
14348
14223
|
const user = {
|
|
14349
14224
|
expired: oidcUser.expired,
|
|
14350
14225
|
idToken: oidcUser.id_token,
|
|
@@ -15769,9 +15644,7 @@ class JsonRpcError extends Error {
|
|
|
15769
15644
|
}
|
|
15770
15645
|
|
|
15771
15646
|
const MESSAGE_TO_SIGN = 'Only sign this message from Immutable Passport';
|
|
15772
|
-
async function registerZkEvmUser({ authManager,
|
|
15773
|
-
const web3Provider = new Web3Provider(magicProvider);
|
|
15774
|
-
const ethSigner = web3Provider.getSigner();
|
|
15647
|
+
async function registerZkEvmUser({ authManager, ethSigner, multiRollupApiClients, accessToken, jsonRpcProvider, }) {
|
|
15775
15648
|
const ethereumAddress = await ethSigner.getAddress();
|
|
15776
15649
|
const ethereumSignature = await signRaw(MESSAGE_TO_SIGN, ethSigner);
|
|
15777
15650
|
const headers = { Authorization: `Bearer ${accessToken}` };
|
|
@@ -15801,32 +15674,6 @@ async function registerZkEvmUser({ authManager, magicProvider, multiRollupApiCli
|
|
|
15801
15674
|
return user;
|
|
15802
15675
|
}
|
|
15803
15676
|
|
|
15804
|
-
const loginZkEvmUser = async ({ authManager, magicAdapter, multiRollupApiClients, jsonRpcProvider, }) => {
|
|
15805
|
-
const user = await authManager.getUserOrLogin();
|
|
15806
|
-
if (!user.idToken) {
|
|
15807
|
-
throw new Error('User is missing idToken');
|
|
15808
|
-
}
|
|
15809
|
-
const magicProvider = await magicAdapter.login(user.idToken);
|
|
15810
|
-
if (!user.zkEvm) {
|
|
15811
|
-
// Generate counterfactual address and retrieve updated Auth0 user
|
|
15812
|
-
const userZkevm = await registerZkEvmUser({
|
|
15813
|
-
authManager,
|
|
15814
|
-
magicProvider,
|
|
15815
|
-
multiRollupApiClients,
|
|
15816
|
-
accessToken: user.accessToken,
|
|
15817
|
-
jsonRpcProvider,
|
|
15818
|
-
});
|
|
15819
|
-
return {
|
|
15820
|
-
user: userZkevm,
|
|
15821
|
-
magicProvider,
|
|
15822
|
-
};
|
|
15823
|
-
}
|
|
15824
|
-
return {
|
|
15825
|
-
user: user,
|
|
15826
|
-
magicProvider,
|
|
15827
|
-
};
|
|
15828
|
-
};
|
|
15829
|
-
|
|
15830
15677
|
const transactionRejectedCrossSdkBridgeError = 'Transaction requires confirmation but this functionality is not'
|
|
15831
15678
|
+ ' supported in this environment. Please contact Immutable support if you need to enable this feature.';
|
|
15832
15679
|
const convertBigNumberishToString = (value) => BigNumber.from(value).toString();
|
|
@@ -16022,7 +15869,7 @@ const getMetaTransactions = async (metaTransaction, nonce, chainId, walletAddres
|
|
|
16022
15869
|
}
|
|
16023
15870
|
return [metaTransaction, feeMetaTransaction];
|
|
16024
15871
|
};
|
|
16025
|
-
const sendTransaction = ({ params,
|
|
15872
|
+
const sendTransaction = ({ params, ethSigner, jsonRpcProvider, relayerClient, guardianClient, zkevmAddress, }) => guardianClient
|
|
16026
15873
|
.withConfirmationScreen({ width: 480, height: 720 })(async () => {
|
|
16027
15874
|
const transactionRequest = params[0];
|
|
16028
15875
|
if (!transactionRequest.to) {
|
|
@@ -16030,8 +15877,6 @@ const sendTransaction = ({ params, magicProvider, jsonRpcProvider, relayerClient
|
|
|
16030
15877
|
}
|
|
16031
15878
|
const { chainId } = await jsonRpcProvider.ready;
|
|
16032
15879
|
const chainIdBigNumber = BigNumber.from(chainId);
|
|
16033
|
-
const magicWeb3Provider = new Web3Provider(magicProvider);
|
|
16034
|
-
const signer = magicWeb3Provider.getSigner();
|
|
16035
15880
|
const nonce = await getNonce(jsonRpcProvider, zkevmAddress);
|
|
16036
15881
|
const metaTransaction = {
|
|
16037
15882
|
to: transactionRequest.to,
|
|
@@ -16040,7 +15885,7 @@ const sendTransaction = ({ params, magicProvider, jsonRpcProvider, relayerClient
|
|
|
16040
15885
|
value: transactionRequest.value,
|
|
16041
15886
|
revertOnError: true,
|
|
16042
15887
|
};
|
|
16043
|
-
const metaTransactions = await getMetaTransactions(metaTransaction, nonce, chainIdBigNumber, zkevmAddress,
|
|
15888
|
+
const metaTransactions = await getMetaTransactions(metaTransaction, nonce, chainIdBigNumber, zkevmAddress, ethSigner, relayerClient);
|
|
16044
15889
|
await guardianClient.validateEVMTransaction({
|
|
16045
15890
|
chainId: getEip155ChainId(chainId),
|
|
16046
15891
|
nonce: convertBigNumberishToString(nonce),
|
|
@@ -16048,7 +15893,7 @@ const sendTransaction = ({ params, magicProvider, jsonRpcProvider, relayerClient
|
|
|
16048
15893
|
});
|
|
16049
15894
|
// NOTE: We sign again because we now are adding the fee transaction, so the
|
|
16050
15895
|
// whole payload is different and needs a new signature.
|
|
16051
|
-
const signedTransactions = await getSignedMetaTransactions(metaTransactions, nonce, chainIdBigNumber, zkevmAddress,
|
|
15896
|
+
const signedTransactions = await getSignedMetaTransactions(metaTransactions, nonce, chainIdBigNumber, zkevmAddress, ethSigner);
|
|
16052
15897
|
const relayerId = await relayerClient.ethSendTransaction(zkevmAddress, signedTransactions);
|
|
16053
15898
|
const retrieveRelayerTransaction = async () => {
|
|
16054
15899
|
const tx = await relayerClient.imGetTransactionByHash(relayerId);
|
|
@@ -16117,7 +15962,7 @@ const transformTypedData = (typedData, chainId) => {
|
|
|
16117
15962
|
}
|
|
16118
15963
|
return transformedTypedData;
|
|
16119
15964
|
};
|
|
16120
|
-
const signTypedDataV4 = async ({ params, method,
|
|
15965
|
+
const signTypedDataV4 = async ({ params, method, ethSigner, jsonRpcProvider, relayerClient, guardianClient, }) => guardianClient
|
|
16121
15966
|
.withConfirmationScreen({ width: 480, height: 720 })(async () => {
|
|
16122
15967
|
const fromAddress = params[0];
|
|
16123
15968
|
const typedDataParam = params[1];
|
|
@@ -16128,106 +15973,158 @@ const signTypedDataV4 = async ({ params, method, magicProvider, jsonRpcProvider,
|
|
|
16128
15973
|
const typedData = transformTypedData(typedDataParam, chainId);
|
|
16129
15974
|
await guardianClient.validateMessage({ chainID: String(chainId), payload: typedData });
|
|
16130
15975
|
const relayerSignature = await relayerClient.imSignTypedData(fromAddress, typedData);
|
|
16131
|
-
|
|
16132
|
-
const signer = magicWeb3Provider.getSigner();
|
|
16133
|
-
return getSignedTypedData(typedData, relayerSignature, BigNumber.from(chainId), fromAddress, signer);
|
|
15976
|
+
return getSignedTypedData(typedData, relayerSignature, BigNumber.from(chainId), fromAddress, ethSigner);
|
|
16134
15977
|
});
|
|
16135
15978
|
|
|
15979
|
+
const isZkEvmUser = (user) => 'zkEvm' in user;
|
|
16136
15980
|
class ZkEvmProvider {
|
|
16137
|
-
authManager;
|
|
16138
|
-
config;
|
|
16139
|
-
|
|
16140
|
-
|
|
16141
|
-
jsonRpcProvider; // Used for read
|
|
16142
|
-
|
|
16143
|
-
|
|
16144
|
-
relayerClient;
|
|
16145
|
-
|
|
16146
|
-
|
|
15981
|
+
#authManager;
|
|
15982
|
+
#config;
|
|
15983
|
+
#eventEmitter;
|
|
15984
|
+
#guardianClient;
|
|
15985
|
+
#jsonRpcProvider; // Used for read
|
|
15986
|
+
#magicAdapter;
|
|
15987
|
+
#multiRollupApiClients;
|
|
15988
|
+
#relayerClient;
|
|
15989
|
+
/**
|
|
15990
|
+
* This property is set during `#initialiseEthSigner` and stores the signer in a promise.
|
|
15991
|
+
* This property is not meant to be accessed directly, but through the
|
|
15992
|
+
* `#getSigner` method.
|
|
15993
|
+
* @see getSigner
|
|
15994
|
+
*/
|
|
15995
|
+
#ethSigner;
|
|
15996
|
+
#signerInitialisationError;
|
|
15997
|
+
#zkEvmAddress;
|
|
16147
15998
|
isPassport = true;
|
|
16148
15999
|
constructor({ authManager, magicAdapter, config, multiRollupApiClients, passportEventEmitter, guardianClient, }) {
|
|
16149
|
-
this
|
|
16150
|
-
this
|
|
16151
|
-
this
|
|
16152
|
-
this
|
|
16000
|
+
this.#authManager = authManager;
|
|
16001
|
+
this.#magicAdapter = magicAdapter;
|
|
16002
|
+
this.#config = config;
|
|
16003
|
+
this.#guardianClient = guardianClient;
|
|
16153
16004
|
if (config.crossSdkBridgeEnabled) {
|
|
16154
16005
|
// JsonRpcProvider by default sets the referrer as "client".
|
|
16155
16006
|
// On Unreal 4 this errors as the browser used is expecting a valid URL.
|
|
16156
|
-
this
|
|
16157
|
-
url: this
|
|
16007
|
+
this.#jsonRpcProvider = new JsonRpcProvider({
|
|
16008
|
+
url: this.#config.zkEvmRpcUrl,
|
|
16158
16009
|
fetchOptions: { referrer: 'http://imtblgamesdk.local' },
|
|
16159
16010
|
});
|
|
16160
16011
|
}
|
|
16161
16012
|
else {
|
|
16162
|
-
this
|
|
16013
|
+
this.#jsonRpcProvider = new JsonRpcProvider(this.#config.zkEvmRpcUrl);
|
|
16163
16014
|
}
|
|
16164
|
-
this
|
|
16165
|
-
|
|
16166
|
-
|
|
16167
|
-
|
|
16168
|
-
|
|
16169
|
-
|
|
16170
|
-
this
|
|
16171
|
-
|
|
16015
|
+
this.#relayerClient = new RelayerClient({
|
|
16016
|
+
config: this.#config,
|
|
16017
|
+
jsonRpcProvider: this.#jsonRpcProvider,
|
|
16018
|
+
authManager: this.#authManager,
|
|
16019
|
+
});
|
|
16020
|
+
this.#multiRollupApiClients = multiRollupApiClients;
|
|
16021
|
+
this.#eventEmitter = new TypedEventEmitter();
|
|
16022
|
+
passportEventEmitter.on(PassportEvents.LOGGED_OUT, this.#handleLogout);
|
|
16023
|
+
}
|
|
16024
|
+
#handleLogout = () => {
|
|
16025
|
+
const shouldEmitAccountsChanged = !!this.#zkEvmAddress;
|
|
16026
|
+
this.#ethSigner = undefined;
|
|
16027
|
+
this.#zkEvmAddress = undefined;
|
|
16172
16028
|
if (shouldEmitAccountsChanged) {
|
|
16173
|
-
this
|
|
16029
|
+
this.#eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, []);
|
|
16174
16030
|
}
|
|
16175
16031
|
};
|
|
16176
|
-
|
|
16177
|
-
|
|
16178
|
-
|
|
16179
|
-
|
|
16032
|
+
/**
|
|
16033
|
+
* This method is called by `eth_requestAccounts` and asynchronously initialises the signer.
|
|
16034
|
+
* The signer is stored in a promise so that it can be retrieved by the provider
|
|
16035
|
+
* when needed.
|
|
16036
|
+
*
|
|
16037
|
+
* If an error is thrown during initialisation, it is stored in the `signerInitialisationError`,
|
|
16038
|
+
* so that it doesn't result in an unhandled promise rejection.
|
|
16039
|
+
*
|
|
16040
|
+
* This error is thrown when the signer is requested through:
|
|
16041
|
+
* @see #getSigner
|
|
16042
|
+
*
|
|
16043
|
+
*/
|
|
16044
|
+
async #initialiseEthSigner(user) {
|
|
16045
|
+
const generateSigner = async () => {
|
|
16046
|
+
const magicRpcProvider = await this.#magicAdapter.login(user.idToken);
|
|
16047
|
+
const web3Provider = new Web3Provider(magicRpcProvider);
|
|
16048
|
+
return web3Provider.getSigner();
|
|
16049
|
+
};
|
|
16050
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
16051
|
+
this.#ethSigner = new Promise(async (resolve) => {
|
|
16052
|
+
try {
|
|
16053
|
+
resolve(await generateSigner());
|
|
16054
|
+
}
|
|
16055
|
+
catch (err) {
|
|
16056
|
+
// Capture and store the initialization error
|
|
16057
|
+
this.#signerInitialisationError = err;
|
|
16058
|
+
resolve(undefined);
|
|
16059
|
+
}
|
|
16060
|
+
});
|
|
16180
16061
|
}
|
|
16181
|
-
async
|
|
16062
|
+
async #getSigner() {
|
|
16063
|
+
const ethSigner = await this.#ethSigner;
|
|
16064
|
+
// Throw the stored error if the signers failed to initialise
|
|
16065
|
+
if (typeof ethSigner === 'undefined') {
|
|
16066
|
+
if (typeof this.#signerInitialisationError !== 'undefined') {
|
|
16067
|
+
throw this.#signerInitialisationError;
|
|
16068
|
+
}
|
|
16069
|
+
throw new Error('Signer failed to initialise');
|
|
16070
|
+
}
|
|
16071
|
+
return ethSigner;
|
|
16072
|
+
}
|
|
16073
|
+
async #performRequest(request) {
|
|
16182
16074
|
switch (request.method) {
|
|
16183
16075
|
case 'eth_requestAccounts': {
|
|
16184
|
-
if (this
|
|
16185
|
-
return [this
|
|
16076
|
+
if (this.#zkEvmAddress) {
|
|
16077
|
+
return [this.#zkEvmAddress];
|
|
16186
16078
|
}
|
|
16187
|
-
const
|
|
16188
|
-
|
|
16189
|
-
|
|
16190
|
-
|
|
16191
|
-
|
|
16192
|
-
|
|
16193
|
-
|
|
16194
|
-
|
|
16195
|
-
|
|
16196
|
-
|
|
16197
|
-
|
|
16198
|
-
|
|
16199
|
-
|
|
16200
|
-
|
|
16201
|
-
|
|
16079
|
+
const user = await this.#authManager.getUserOrLogin();
|
|
16080
|
+
this.#initialiseEthSigner(user);
|
|
16081
|
+
if (!isZkEvmUser(user)) {
|
|
16082
|
+
const ethSigner = await this.#getSigner();
|
|
16083
|
+
const userZkEvm = await registerZkEvmUser({
|
|
16084
|
+
ethSigner,
|
|
16085
|
+
authManager: this.#authManager,
|
|
16086
|
+
multiRollupApiClients: this.#multiRollupApiClients,
|
|
16087
|
+
accessToken: user.accessToken,
|
|
16088
|
+
jsonRpcProvider: this.#jsonRpcProvider,
|
|
16089
|
+
});
|
|
16090
|
+
this.#zkEvmAddress = userZkEvm.zkEvm.ethAddress;
|
|
16091
|
+
}
|
|
16092
|
+
else {
|
|
16093
|
+
this.#zkEvmAddress = user.zkEvm.ethAddress;
|
|
16094
|
+
}
|
|
16095
|
+
this.#eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, [this.#zkEvmAddress]);
|
|
16096
|
+
return [this.#zkEvmAddress];
|
|
16202
16097
|
}
|
|
16203
16098
|
case 'eth_sendTransaction': {
|
|
16204
|
-
if (!this
|
|
16099
|
+
if (!this.#zkEvmAddress) {
|
|
16205
16100
|
throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorised - call eth_requestAccounts first');
|
|
16206
16101
|
}
|
|
16102
|
+
const ethSigner = await this.#getSigner();
|
|
16207
16103
|
return sendTransaction({
|
|
16208
16104
|
params: request.params || [],
|
|
16209
|
-
|
|
16210
|
-
guardianClient: this
|
|
16211
|
-
jsonRpcProvider: this
|
|
16212
|
-
relayerClient: this
|
|
16213
|
-
zkevmAddress: this
|
|
16105
|
+
ethSigner,
|
|
16106
|
+
guardianClient: this.#guardianClient,
|
|
16107
|
+
jsonRpcProvider: this.#jsonRpcProvider,
|
|
16108
|
+
relayerClient: this.#relayerClient,
|
|
16109
|
+
zkevmAddress: this.#zkEvmAddress,
|
|
16214
16110
|
});
|
|
16215
16111
|
}
|
|
16216
16112
|
case 'eth_accounts': {
|
|
16217
|
-
return this
|
|
16113
|
+
return this.#zkEvmAddress ? [this.#zkEvmAddress] : [];
|
|
16218
16114
|
}
|
|
16219
16115
|
case 'eth_signTypedData':
|
|
16220
16116
|
case 'eth_signTypedData_v4': {
|
|
16221
|
-
if (!this
|
|
16117
|
+
if (!this.#zkEvmAddress) {
|
|
16222
16118
|
throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorised - call eth_requestAccounts first');
|
|
16223
16119
|
}
|
|
16120
|
+
const ethSigner = await this.#getSigner();
|
|
16224
16121
|
return signTypedDataV4({
|
|
16225
16122
|
method: request.method,
|
|
16226
16123
|
params: request.params || [],
|
|
16227
|
-
|
|
16228
|
-
jsonRpcProvider: this
|
|
16229
|
-
relayerClient: this
|
|
16230
|
-
guardianClient: this
|
|
16124
|
+
ethSigner,
|
|
16125
|
+
jsonRpcProvider: this.#jsonRpcProvider,
|
|
16126
|
+
relayerClient: this.#relayerClient,
|
|
16127
|
+
guardianClient: this.#guardianClient,
|
|
16231
16128
|
});
|
|
16232
16129
|
}
|
|
16233
16130
|
// Pass through methods
|
|
@@ -16244,17 +16141,17 @@ class ZkEvmProvider {
|
|
|
16244
16141
|
case 'eth_getTransactionByHash':
|
|
16245
16142
|
case 'eth_getTransactionReceipt':
|
|
16246
16143
|
case 'eth_getTransactionCount': {
|
|
16247
|
-
return this
|
|
16144
|
+
return this.#jsonRpcProvider.send(request.method, request.params || []);
|
|
16248
16145
|
}
|
|
16249
16146
|
default: {
|
|
16250
16147
|
throw new JsonRpcError(ProviderErrorCode.UNSUPPORTED_METHOD, 'Method not supported');
|
|
16251
16148
|
}
|
|
16252
16149
|
}
|
|
16253
16150
|
}
|
|
16254
|
-
async performJsonRpcRequest(request) {
|
|
16151
|
+
async #performJsonRpcRequest(request) {
|
|
16255
16152
|
const { id, jsonrpc } = request;
|
|
16256
16153
|
try {
|
|
16257
|
-
const result = await this
|
|
16154
|
+
const result = await this.#performRequest(request);
|
|
16258
16155
|
return {
|
|
16259
16156
|
id,
|
|
16260
16157
|
jsonrpc,
|
|
@@ -16281,7 +16178,7 @@ class ZkEvmProvider {
|
|
|
16281
16178
|
}
|
|
16282
16179
|
async request(request) {
|
|
16283
16180
|
try {
|
|
16284
|
-
return this
|
|
16181
|
+
return this.#performRequest(request);
|
|
16285
16182
|
}
|
|
16286
16183
|
catch (error) {
|
|
16287
16184
|
if (error instanceof JsonRpcError) {
|
|
@@ -16298,14 +16195,14 @@ class ZkEvmProvider {
|
|
|
16298
16195
|
throw new Error('No callback provided');
|
|
16299
16196
|
}
|
|
16300
16197
|
if (Array.isArray(request)) {
|
|
16301
|
-
Promise.all(request.map(this
|
|
16198
|
+
Promise.all(request.map(this.#performJsonRpcRequest)).then((result) => {
|
|
16302
16199
|
callback(null, result);
|
|
16303
16200
|
}).catch((error) => {
|
|
16304
16201
|
callback(error, []);
|
|
16305
16202
|
});
|
|
16306
16203
|
}
|
|
16307
16204
|
else {
|
|
16308
|
-
this
|
|
16205
|
+
this.#performJsonRpcRequest(request).then((result) => {
|
|
16309
16206
|
callback(null, result);
|
|
16310
16207
|
}).catch((error) => {
|
|
16311
16208
|
callback(error, null);
|
|
@@ -16337,15 +16234,15 @@ class ZkEvmProvider {
|
|
|
16337
16234
|
return this.sendAsync(request, callbackOrParams);
|
|
16338
16235
|
}
|
|
16339
16236
|
if (!Array.isArray(request) && typeof request === 'object') {
|
|
16340
|
-
return this
|
|
16237
|
+
return this.#performJsonRpcRequest(request);
|
|
16341
16238
|
}
|
|
16342
16239
|
throw new JsonRpcError(RpcErrorCode.INVALID_REQUEST, 'Invalid request');
|
|
16343
16240
|
}
|
|
16344
16241
|
on(event, listener) {
|
|
16345
|
-
this
|
|
16242
|
+
this.#eventEmitter.on(event, listener);
|
|
16346
16243
|
}
|
|
16347
16244
|
removeListener(event, listener) {
|
|
16348
|
-
this
|
|
16245
|
+
this.#eventEmitter.removeListener(event, listener);
|
|
16349
16246
|
}
|
|
16350
16247
|
}
|
|
16351
16248
|
|
package/dist/x.js
CHANGED
|
@@ -136,7 +136,7 @@ const flattenProperties = (properties) => {
|
|
|
136
136
|
};
|
|
137
137
|
|
|
138
138
|
// WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
|
|
139
|
-
const SDK_VERSION = '1.7.3-alpha.
|
|
139
|
+
const SDK_VERSION = '1.7.3-alpha.2';
|
|
140
140
|
const getReferrer = () => {
|
|
141
141
|
if (isNode()) {
|
|
142
142
|
return '';
|
|
@@ -328,7 +328,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
328
328
|
chainID,
|
|
329
329
|
coreContractAddress,
|
|
330
330
|
registrationContractAddress,
|
|
331
|
-
sdkVersion: 'ts-immutable-sdk-1.7.3-alpha.
|
|
331
|
+
sdkVersion: 'ts-immutable-sdk-1.7.3-alpha.2',
|
|
332
332
|
});
|
|
333
333
|
/**
|
|
334
334
|
* Sets `sdkVersion` at the time of build
|
package/package.json
CHANGED