@imtbl/sdk 1.7.2 → 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 +78 -34
- package/dist/blockchain_data.js +2 -2
- 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 -32
- 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 -143
- package/dist/index.d.ts +81 -35
- package/dist/index.js +200 -143
- package/dist/orderbook.js +1 -1
- package/dist/passport.js +136 -112
- package/dist/x.js +2 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -174,7 +174,7 @@ const flattenProperties$1 = (properties) => {
|
|
|
174
174
|
};
|
|
175
175
|
|
|
176
176
|
// WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
|
|
177
|
-
const SDK_VERSION$1 = '1.7.2';
|
|
177
|
+
const SDK_VERSION$1 = '1.7.3-alpha.2';
|
|
178
178
|
const getReferrer$1 = () => {
|
|
179
179
|
if (isNode$1()) {
|
|
180
180
|
return '';
|
|
@@ -11298,7 +11298,7 @@ class MultiRollupApiClients {
|
|
|
11298
11298
|
}
|
|
11299
11299
|
|
|
11300
11300
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
11301
|
-
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.7.2' };
|
|
11301
|
+
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.7.3-alpha.2' };
|
|
11302
11302
|
const createConfig = ({ basePath, headers, }) => {
|
|
11303
11303
|
if (!basePath.trim()) {
|
|
11304
11304
|
throw Error('basePath can not be empty');
|
|
@@ -11370,7 +11370,7 @@ class APIError extends Error {
|
|
|
11370
11370
|
|
|
11371
11371
|
/* eslint-disable implicit-arrow-linebreak */
|
|
11372
11372
|
const defaultHeaders = {
|
|
11373
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.7.2',
|
|
11373
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.7.3-alpha.2',
|
|
11374
11374
|
};
|
|
11375
11375
|
/**
|
|
11376
11376
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -11803,7 +11803,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
11803
11803
|
chainID,
|
|
11804
11804
|
coreContractAddress,
|
|
11805
11805
|
registrationContractAddress,
|
|
11806
|
-
sdkVersion: 'ts-immutable-sdk-1.7.2',
|
|
11806
|
+
sdkVersion: 'ts-immutable-sdk-1.7.3-alpha.2',
|
|
11807
11807
|
});
|
|
11808
11808
|
/**
|
|
11809
11809
|
* Sets `sdkVersion` at the time of build
|
|
@@ -16450,7 +16450,6 @@ const getAuthConfiguration = (config) => {
|
|
|
16450
16450
|
end_session_endpoint: endSessionEndpoint,
|
|
16451
16451
|
},
|
|
16452
16452
|
mergeClaims: true,
|
|
16453
|
-
loadUserInfo: true,
|
|
16454
16453
|
scope: oidcConfiguration.scope,
|
|
16455
16454
|
userStore,
|
|
16456
16455
|
};
|
|
@@ -16491,7 +16490,10 @@ class AuthManager {
|
|
|
16491
16490
|
this.logoutMode = config.oidcConfiguration.logoutMode || 'redirect';
|
|
16492
16491
|
}
|
|
16493
16492
|
static mapOidcUserToDomainModel = (oidcUser) => {
|
|
16494
|
-
|
|
16493
|
+
let passport;
|
|
16494
|
+
if (oidcUser.id_token) {
|
|
16495
|
+
passport = jwt_decode(oidcUser.id_token)?.passport;
|
|
16496
|
+
}
|
|
16495
16497
|
const user = {
|
|
16496
16498
|
expired: oidcUser.expired,
|
|
16497
16499
|
idToken: oidcUser.id_token,
|
|
@@ -17916,9 +17918,7 @@ class JsonRpcError extends Error {
|
|
|
17916
17918
|
}
|
|
17917
17919
|
|
|
17918
17920
|
const MESSAGE_TO_SIGN = 'Only sign this message from Immutable Passport';
|
|
17919
|
-
async function registerZkEvmUser({ authManager,
|
|
17920
|
-
const web3Provider = new providers.Web3Provider(magicProvider);
|
|
17921
|
-
const ethSigner = web3Provider.getSigner();
|
|
17921
|
+
async function registerZkEvmUser({ authManager, ethSigner, multiRollupApiClients, accessToken, jsonRpcProvider, }) {
|
|
17922
17922
|
const ethereumAddress = await ethSigner.getAddress();
|
|
17923
17923
|
const ethereumSignature = await signRaw(MESSAGE_TO_SIGN, ethSigner);
|
|
17924
17924
|
const headers = { Authorization: `Bearer ${accessToken}` };
|
|
@@ -17948,32 +17948,6 @@ async function registerZkEvmUser({ authManager, magicProvider, multiRollupApiCli
|
|
|
17948
17948
|
return user;
|
|
17949
17949
|
}
|
|
17950
17950
|
|
|
17951
|
-
const loginZkEvmUser = async ({ authManager, magicAdapter, multiRollupApiClients, jsonRpcProvider, }) => {
|
|
17952
|
-
const user = await authManager.getUserOrLogin();
|
|
17953
|
-
if (!user.idToken) {
|
|
17954
|
-
throw new Error('User is missing idToken');
|
|
17955
|
-
}
|
|
17956
|
-
const magicProvider = await magicAdapter.login(user.idToken);
|
|
17957
|
-
if (!user.zkEvm) {
|
|
17958
|
-
// Generate counterfactual address and retrieve updated Auth0 user
|
|
17959
|
-
const userZkevm = await registerZkEvmUser({
|
|
17960
|
-
authManager,
|
|
17961
|
-
magicProvider,
|
|
17962
|
-
multiRollupApiClients,
|
|
17963
|
-
accessToken: user.accessToken,
|
|
17964
|
-
jsonRpcProvider,
|
|
17965
|
-
});
|
|
17966
|
-
return {
|
|
17967
|
-
user: userZkevm,
|
|
17968
|
-
magicProvider,
|
|
17969
|
-
};
|
|
17970
|
-
}
|
|
17971
|
-
return {
|
|
17972
|
-
user: user,
|
|
17973
|
-
magicProvider,
|
|
17974
|
-
};
|
|
17975
|
-
};
|
|
17976
|
-
|
|
17977
17951
|
const transactionRejectedCrossSdkBridgeError = 'Transaction requires confirmation but this functionality is not'
|
|
17978
17952
|
+ ' supported in this environment. Please contact Immutable support if you need to enable this feature.';
|
|
17979
17953
|
const convertBigNumberishToString = (value) => ethers.BigNumber.from(value).toString();
|
|
@@ -18169,7 +18143,7 @@ const getMetaTransactions = async (metaTransaction, nonce, chainId, walletAddres
|
|
|
18169
18143
|
}
|
|
18170
18144
|
return [metaTransaction, feeMetaTransaction];
|
|
18171
18145
|
};
|
|
18172
|
-
const sendTransaction$1 = ({ params,
|
|
18146
|
+
const sendTransaction$1 = ({ params, ethSigner, jsonRpcProvider, relayerClient, guardianClient, zkevmAddress, }) => guardianClient
|
|
18173
18147
|
.withConfirmationScreen({ width: 480, height: 720 })(async () => {
|
|
18174
18148
|
const transactionRequest = params[0];
|
|
18175
18149
|
if (!transactionRequest.to) {
|
|
@@ -18177,8 +18151,6 @@ const sendTransaction$1 = ({ params, magicProvider, jsonRpcProvider, relayerClie
|
|
|
18177
18151
|
}
|
|
18178
18152
|
const { chainId } = await jsonRpcProvider.ready;
|
|
18179
18153
|
const chainIdBigNumber = ethers.BigNumber.from(chainId);
|
|
18180
|
-
const magicWeb3Provider = new providers.Web3Provider(magicProvider);
|
|
18181
|
-
const signer = magicWeb3Provider.getSigner();
|
|
18182
18154
|
const nonce = await getNonce(jsonRpcProvider, zkevmAddress);
|
|
18183
18155
|
const metaTransaction = {
|
|
18184
18156
|
to: transactionRequest.to,
|
|
@@ -18187,7 +18159,7 @@ const sendTransaction$1 = ({ params, magicProvider, jsonRpcProvider, relayerClie
|
|
|
18187
18159
|
value: transactionRequest.value,
|
|
18188
18160
|
revertOnError: true,
|
|
18189
18161
|
};
|
|
18190
|
-
const metaTransactions = await getMetaTransactions(metaTransaction, nonce, chainIdBigNumber, zkevmAddress,
|
|
18162
|
+
const metaTransactions = await getMetaTransactions(metaTransaction, nonce, chainIdBigNumber, zkevmAddress, ethSigner, relayerClient);
|
|
18191
18163
|
await guardianClient.validateEVMTransaction({
|
|
18192
18164
|
chainId: getEip155ChainId(chainId),
|
|
18193
18165
|
nonce: convertBigNumberishToString(nonce),
|
|
@@ -18195,7 +18167,7 @@ const sendTransaction$1 = ({ params, magicProvider, jsonRpcProvider, relayerClie
|
|
|
18195
18167
|
});
|
|
18196
18168
|
// NOTE: We sign again because we now are adding the fee transaction, so the
|
|
18197
18169
|
// whole payload is different and needs a new signature.
|
|
18198
|
-
const signedTransactions = await getSignedMetaTransactions(metaTransactions, nonce, chainIdBigNumber, zkevmAddress,
|
|
18170
|
+
const signedTransactions = await getSignedMetaTransactions(metaTransactions, nonce, chainIdBigNumber, zkevmAddress, ethSigner);
|
|
18199
18171
|
const relayerId = await relayerClient.ethSendTransaction(zkevmAddress, signedTransactions);
|
|
18200
18172
|
const retrieveRelayerTransaction = async () => {
|
|
18201
18173
|
const tx = await relayerClient.imGetTransactionByHash(relayerId);
|
|
@@ -18264,7 +18236,7 @@ const transformTypedData = (typedData, chainId) => {
|
|
|
18264
18236
|
}
|
|
18265
18237
|
return transformedTypedData;
|
|
18266
18238
|
};
|
|
18267
|
-
const signTypedDataV4 = async ({ params, method,
|
|
18239
|
+
const signTypedDataV4 = async ({ params, method, ethSigner, jsonRpcProvider, relayerClient, guardianClient, }) => guardianClient
|
|
18268
18240
|
.withConfirmationScreen({ width: 480, height: 720 })(async () => {
|
|
18269
18241
|
const fromAddress = params[0];
|
|
18270
18242
|
const typedDataParam = params[1];
|
|
@@ -18275,106 +18247,158 @@ const signTypedDataV4 = async ({ params, method, magicProvider, jsonRpcProvider,
|
|
|
18275
18247
|
const typedData = transformTypedData(typedDataParam, chainId);
|
|
18276
18248
|
await guardianClient.validateMessage({ chainID: String(chainId), payload: typedData });
|
|
18277
18249
|
const relayerSignature = await relayerClient.imSignTypedData(fromAddress, typedData);
|
|
18278
|
-
|
|
18279
|
-
const signer = magicWeb3Provider.getSigner();
|
|
18280
|
-
return getSignedTypedData(typedData, relayerSignature, ethers.BigNumber.from(chainId), fromAddress, signer);
|
|
18250
|
+
return getSignedTypedData(typedData, relayerSignature, ethers.BigNumber.from(chainId), fromAddress, ethSigner);
|
|
18281
18251
|
});
|
|
18282
18252
|
|
|
18253
|
+
const isZkEvmUser = (user) => 'zkEvm' in user;
|
|
18283
18254
|
class ZkEvmProvider {
|
|
18284
|
-
authManager;
|
|
18285
|
-
config;
|
|
18286
|
-
|
|
18287
|
-
|
|
18288
|
-
jsonRpcProvider; // Used for read
|
|
18289
|
-
|
|
18290
|
-
|
|
18291
|
-
relayerClient;
|
|
18292
|
-
|
|
18293
|
-
|
|
18255
|
+
#authManager;
|
|
18256
|
+
#config;
|
|
18257
|
+
#eventEmitter;
|
|
18258
|
+
#guardianClient;
|
|
18259
|
+
#jsonRpcProvider; // Used for read
|
|
18260
|
+
#magicAdapter;
|
|
18261
|
+
#multiRollupApiClients;
|
|
18262
|
+
#relayerClient;
|
|
18263
|
+
/**
|
|
18264
|
+
* This property is set during `#initialiseEthSigner` and stores the signer in a promise.
|
|
18265
|
+
* This property is not meant to be accessed directly, but through the
|
|
18266
|
+
* `#getSigner` method.
|
|
18267
|
+
* @see getSigner
|
|
18268
|
+
*/
|
|
18269
|
+
#ethSigner;
|
|
18270
|
+
#signerInitialisationError;
|
|
18271
|
+
#zkEvmAddress;
|
|
18294
18272
|
isPassport = true;
|
|
18295
18273
|
constructor({ authManager, magicAdapter, config, multiRollupApiClients, passportEventEmitter, guardianClient, }) {
|
|
18296
|
-
this
|
|
18297
|
-
this
|
|
18298
|
-
this
|
|
18299
|
-
this
|
|
18274
|
+
this.#authManager = authManager;
|
|
18275
|
+
this.#magicAdapter = magicAdapter;
|
|
18276
|
+
this.#config = config;
|
|
18277
|
+
this.#guardianClient = guardianClient;
|
|
18300
18278
|
if (config.crossSdkBridgeEnabled) {
|
|
18301
18279
|
// JsonRpcProvider by default sets the referrer as "client".
|
|
18302
18280
|
// On Unreal 4 this errors as the browser used is expecting a valid URL.
|
|
18303
|
-
this
|
|
18304
|
-
url: this
|
|
18281
|
+
this.#jsonRpcProvider = new providers.JsonRpcProvider({
|
|
18282
|
+
url: this.#config.zkEvmRpcUrl,
|
|
18305
18283
|
fetchOptions: { referrer: 'http://imtblgamesdk.local' },
|
|
18306
18284
|
});
|
|
18307
18285
|
}
|
|
18308
18286
|
else {
|
|
18309
|
-
this
|
|
18287
|
+
this.#jsonRpcProvider = new providers.JsonRpcProvider(this.#config.zkEvmRpcUrl);
|
|
18310
18288
|
}
|
|
18311
|
-
this
|
|
18312
|
-
|
|
18313
|
-
|
|
18314
|
-
|
|
18315
|
-
|
|
18316
|
-
|
|
18317
|
-
this
|
|
18318
|
-
|
|
18289
|
+
this.#relayerClient = new RelayerClient({
|
|
18290
|
+
config: this.#config,
|
|
18291
|
+
jsonRpcProvider: this.#jsonRpcProvider,
|
|
18292
|
+
authManager: this.#authManager,
|
|
18293
|
+
});
|
|
18294
|
+
this.#multiRollupApiClients = multiRollupApiClients;
|
|
18295
|
+
this.#eventEmitter = new TypedEventEmitter();
|
|
18296
|
+
passportEventEmitter.on(PassportEvents.LOGGED_OUT, this.#handleLogout);
|
|
18297
|
+
}
|
|
18298
|
+
#handleLogout = () => {
|
|
18299
|
+
const shouldEmitAccountsChanged = !!this.#zkEvmAddress;
|
|
18300
|
+
this.#ethSigner = undefined;
|
|
18301
|
+
this.#zkEvmAddress = undefined;
|
|
18319
18302
|
if (shouldEmitAccountsChanged) {
|
|
18320
|
-
this
|
|
18303
|
+
this.#eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, []);
|
|
18321
18304
|
}
|
|
18322
18305
|
};
|
|
18323
|
-
|
|
18324
|
-
|
|
18325
|
-
|
|
18326
|
-
|
|
18306
|
+
/**
|
|
18307
|
+
* This method is called by `eth_requestAccounts` and asynchronously initialises the signer.
|
|
18308
|
+
* The signer is stored in a promise so that it can be retrieved by the provider
|
|
18309
|
+
* when needed.
|
|
18310
|
+
*
|
|
18311
|
+
* If an error is thrown during initialisation, it is stored in the `signerInitialisationError`,
|
|
18312
|
+
* so that it doesn't result in an unhandled promise rejection.
|
|
18313
|
+
*
|
|
18314
|
+
* This error is thrown when the signer is requested through:
|
|
18315
|
+
* @see #getSigner
|
|
18316
|
+
*
|
|
18317
|
+
*/
|
|
18318
|
+
async #initialiseEthSigner(user) {
|
|
18319
|
+
const generateSigner = async () => {
|
|
18320
|
+
const magicRpcProvider = await this.#magicAdapter.login(user.idToken);
|
|
18321
|
+
const web3Provider = new providers.Web3Provider(magicRpcProvider);
|
|
18322
|
+
return web3Provider.getSigner();
|
|
18323
|
+
};
|
|
18324
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
18325
|
+
this.#ethSigner = new Promise(async (resolve) => {
|
|
18326
|
+
try {
|
|
18327
|
+
resolve(await generateSigner());
|
|
18328
|
+
}
|
|
18329
|
+
catch (err) {
|
|
18330
|
+
// Capture and store the initialization error
|
|
18331
|
+
this.#signerInitialisationError = err;
|
|
18332
|
+
resolve(undefined);
|
|
18333
|
+
}
|
|
18334
|
+
});
|
|
18327
18335
|
}
|
|
18328
|
-
async
|
|
18336
|
+
async #getSigner() {
|
|
18337
|
+
const ethSigner = await this.#ethSigner;
|
|
18338
|
+
// Throw the stored error if the signers failed to initialise
|
|
18339
|
+
if (typeof ethSigner === 'undefined') {
|
|
18340
|
+
if (typeof this.#signerInitialisationError !== 'undefined') {
|
|
18341
|
+
throw this.#signerInitialisationError;
|
|
18342
|
+
}
|
|
18343
|
+
throw new Error('Signer failed to initialise');
|
|
18344
|
+
}
|
|
18345
|
+
return ethSigner;
|
|
18346
|
+
}
|
|
18347
|
+
async #performRequest(request) {
|
|
18329
18348
|
switch (request.method) {
|
|
18330
18349
|
case 'eth_requestAccounts': {
|
|
18331
|
-
if (this
|
|
18332
|
-
return [this
|
|
18350
|
+
if (this.#zkEvmAddress) {
|
|
18351
|
+
return [this.#zkEvmAddress];
|
|
18333
18352
|
}
|
|
18334
|
-
const
|
|
18335
|
-
|
|
18336
|
-
|
|
18337
|
-
|
|
18338
|
-
|
|
18339
|
-
|
|
18340
|
-
|
|
18341
|
-
|
|
18342
|
-
|
|
18343
|
-
|
|
18344
|
-
|
|
18345
|
-
|
|
18346
|
-
|
|
18347
|
-
|
|
18348
|
-
|
|
18353
|
+
const user = await this.#authManager.getUserOrLogin();
|
|
18354
|
+
this.#initialiseEthSigner(user);
|
|
18355
|
+
if (!isZkEvmUser(user)) {
|
|
18356
|
+
const ethSigner = await this.#getSigner();
|
|
18357
|
+
const userZkEvm = await registerZkEvmUser({
|
|
18358
|
+
ethSigner,
|
|
18359
|
+
authManager: this.#authManager,
|
|
18360
|
+
multiRollupApiClients: this.#multiRollupApiClients,
|
|
18361
|
+
accessToken: user.accessToken,
|
|
18362
|
+
jsonRpcProvider: this.#jsonRpcProvider,
|
|
18363
|
+
});
|
|
18364
|
+
this.#zkEvmAddress = userZkEvm.zkEvm.ethAddress;
|
|
18365
|
+
}
|
|
18366
|
+
else {
|
|
18367
|
+
this.#zkEvmAddress = user.zkEvm.ethAddress;
|
|
18368
|
+
}
|
|
18369
|
+
this.#eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, [this.#zkEvmAddress]);
|
|
18370
|
+
return [this.#zkEvmAddress];
|
|
18349
18371
|
}
|
|
18350
18372
|
case 'eth_sendTransaction': {
|
|
18351
|
-
if (!this
|
|
18373
|
+
if (!this.#zkEvmAddress) {
|
|
18352
18374
|
throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorised - call eth_requestAccounts first');
|
|
18353
18375
|
}
|
|
18376
|
+
const ethSigner = await this.#getSigner();
|
|
18354
18377
|
return sendTransaction$1({
|
|
18355
18378
|
params: request.params || [],
|
|
18356
|
-
|
|
18357
|
-
guardianClient: this
|
|
18358
|
-
jsonRpcProvider: this
|
|
18359
|
-
relayerClient: this
|
|
18360
|
-
zkevmAddress: this
|
|
18379
|
+
ethSigner,
|
|
18380
|
+
guardianClient: this.#guardianClient,
|
|
18381
|
+
jsonRpcProvider: this.#jsonRpcProvider,
|
|
18382
|
+
relayerClient: this.#relayerClient,
|
|
18383
|
+
zkevmAddress: this.#zkEvmAddress,
|
|
18361
18384
|
});
|
|
18362
18385
|
}
|
|
18363
18386
|
case 'eth_accounts': {
|
|
18364
|
-
return this
|
|
18387
|
+
return this.#zkEvmAddress ? [this.#zkEvmAddress] : [];
|
|
18365
18388
|
}
|
|
18366
18389
|
case 'eth_signTypedData':
|
|
18367
18390
|
case 'eth_signTypedData_v4': {
|
|
18368
|
-
if (!this
|
|
18391
|
+
if (!this.#zkEvmAddress) {
|
|
18369
18392
|
throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorised - call eth_requestAccounts first');
|
|
18370
18393
|
}
|
|
18394
|
+
const ethSigner = await this.#getSigner();
|
|
18371
18395
|
return signTypedDataV4({
|
|
18372
18396
|
method: request.method,
|
|
18373
18397
|
params: request.params || [],
|
|
18374
|
-
|
|
18375
|
-
jsonRpcProvider: this
|
|
18376
|
-
relayerClient: this
|
|
18377
|
-
guardianClient: this
|
|
18398
|
+
ethSigner,
|
|
18399
|
+
jsonRpcProvider: this.#jsonRpcProvider,
|
|
18400
|
+
relayerClient: this.#relayerClient,
|
|
18401
|
+
guardianClient: this.#guardianClient,
|
|
18378
18402
|
});
|
|
18379
18403
|
}
|
|
18380
18404
|
// Pass through methods
|
|
@@ -18391,17 +18415,17 @@ class ZkEvmProvider {
|
|
|
18391
18415
|
case 'eth_getTransactionByHash':
|
|
18392
18416
|
case 'eth_getTransactionReceipt':
|
|
18393
18417
|
case 'eth_getTransactionCount': {
|
|
18394
|
-
return this
|
|
18418
|
+
return this.#jsonRpcProvider.send(request.method, request.params || []);
|
|
18395
18419
|
}
|
|
18396
18420
|
default: {
|
|
18397
18421
|
throw new JsonRpcError(ProviderErrorCode.UNSUPPORTED_METHOD, 'Method not supported');
|
|
18398
18422
|
}
|
|
18399
18423
|
}
|
|
18400
18424
|
}
|
|
18401
|
-
async performJsonRpcRequest(request) {
|
|
18425
|
+
async #performJsonRpcRequest(request) {
|
|
18402
18426
|
const { id, jsonrpc } = request;
|
|
18403
18427
|
try {
|
|
18404
|
-
const result = await this
|
|
18428
|
+
const result = await this.#performRequest(request);
|
|
18405
18429
|
return {
|
|
18406
18430
|
id,
|
|
18407
18431
|
jsonrpc,
|
|
@@ -18428,7 +18452,7 @@ class ZkEvmProvider {
|
|
|
18428
18452
|
}
|
|
18429
18453
|
async request(request) {
|
|
18430
18454
|
try {
|
|
18431
|
-
return this
|
|
18455
|
+
return this.#performRequest(request);
|
|
18432
18456
|
}
|
|
18433
18457
|
catch (error) {
|
|
18434
18458
|
if (error instanceof JsonRpcError) {
|
|
@@ -18445,14 +18469,14 @@ class ZkEvmProvider {
|
|
|
18445
18469
|
throw new Error('No callback provided');
|
|
18446
18470
|
}
|
|
18447
18471
|
if (Array.isArray(request)) {
|
|
18448
|
-
Promise.all(request.map(this
|
|
18472
|
+
Promise.all(request.map(this.#performJsonRpcRequest)).then((result) => {
|
|
18449
18473
|
callback(null, result);
|
|
18450
18474
|
}).catch((error) => {
|
|
18451
18475
|
callback(error, []);
|
|
18452
18476
|
});
|
|
18453
18477
|
}
|
|
18454
18478
|
else {
|
|
18455
|
-
this
|
|
18479
|
+
this.#performJsonRpcRequest(request).then((result) => {
|
|
18456
18480
|
callback(null, result);
|
|
18457
18481
|
}).catch((error) => {
|
|
18458
18482
|
callback(error, null);
|
|
@@ -18484,15 +18508,15 @@ class ZkEvmProvider {
|
|
|
18484
18508
|
return this.sendAsync(request, callbackOrParams);
|
|
18485
18509
|
}
|
|
18486
18510
|
if (!Array.isArray(request) && typeof request === 'object') {
|
|
18487
|
-
return this
|
|
18511
|
+
return this.#performJsonRpcRequest(request);
|
|
18488
18512
|
}
|
|
18489
18513
|
throw new JsonRpcError(RpcErrorCode.INVALID_REQUEST, 'Invalid request');
|
|
18490
18514
|
}
|
|
18491
18515
|
on(event, listener) {
|
|
18492
|
-
this
|
|
18516
|
+
this.#eventEmitter.on(event, listener);
|
|
18493
18517
|
}
|
|
18494
18518
|
removeListener(event, listener) {
|
|
18495
|
-
this
|
|
18519
|
+
this.#eventEmitter.removeListener(event, listener);
|
|
18496
18520
|
}
|
|
18497
18521
|
}
|
|
18498
18522
|
|
|
@@ -37454,7 +37478,7 @@ const flattenProperties = (properties) => {
|
|
|
37454
37478
|
};
|
|
37455
37479
|
|
|
37456
37480
|
// WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
|
|
37457
|
-
const SDK_VERSION = '1.7.2';
|
|
37481
|
+
const SDK_VERSION = '1.7.3-alpha.2';
|
|
37458
37482
|
const getReferrer = () => {
|
|
37459
37483
|
if (isNode()) {
|
|
37460
37484
|
return '';
|
|
@@ -42622,7 +42646,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
|
|
|
42622
42646
|
maxPriorityFeePerGas: ethers.BigNumber.from(10e9),
|
|
42623
42647
|
};
|
|
42624
42648
|
|
|
42625
|
-
const SDK_VERSION_MARKER = '1.7.2';
|
|
42649
|
+
const SDK_VERSION_MARKER = '1.7.3-alpha.2';
|
|
42626
42650
|
// This SDK version is replaced by the `yarn build` command ran on the root level
|
|
42627
42651
|
const globalPackageVersion = () => SDK_VERSION_MARKER;
|
|
42628
42652
|
|
|
@@ -46242,27 +46266,25 @@ function validateAndBuildVersion(version) {
|
|
|
46242
46266
|
return validatedVersion;
|
|
46243
46267
|
}
|
|
46244
46268
|
|
|
46245
|
-
|
|
46269
|
+
// Loads the checkout widgets bundle from the CDN and appends the script to the document head
|
|
46270
|
+
function loadUnresolvedBundle(tag, scriptId, validVersion) {
|
|
46246
46271
|
if (window === undefined) {
|
|
46247
46272
|
throw new Error('missing window object: please run Checkout client side');
|
|
46248
46273
|
}
|
|
46249
46274
|
if (document === undefined) {
|
|
46250
46275
|
throw new Error('missing document object: please run Checkout client side');
|
|
46251
46276
|
}
|
|
46252
|
-
const scriptId = 'immutable-checkout-widgets-bundle';
|
|
46253
|
-
const validVersion = validateAndBuildVersion(version);
|
|
46254
|
-
// Prevent the script to be loaded more than once
|
|
46255
|
-
// by checking the presence of the script and its version.
|
|
46256
|
-
const initScript = document.getElementById(scriptId);
|
|
46257
|
-
if (initScript)
|
|
46258
|
-
return { loaded: true, element: initScript };
|
|
46259
|
-
const tag = document.createElement('script');
|
|
46260
46277
|
let cdnUrl = `https://cdn.jsdelivr.net/npm/@imtbl/sdk@${validVersion}/dist/browser/checkout/widgets.js`;
|
|
46261
46278
|
tag.setAttribute('id', scriptId);
|
|
46262
46279
|
tag.setAttribute('data-version', validVersion);
|
|
46263
46280
|
tag.setAttribute('src', cdnUrl);
|
|
46264
46281
|
document.head.appendChild(tag);
|
|
46265
|
-
|
|
46282
|
+
}
|
|
46283
|
+
// Gets the CDN url for the split checkout widgets bundle
|
|
46284
|
+
function getWidgetsEsmUrl(version) {
|
|
46285
|
+
const validVersion = validateAndBuildVersion(version);
|
|
46286
|
+
let cdnUrl = `https://cdn.jsdelivr.net/npm/@imtbl/sdk@${validVersion}/dist/browser/checkout/widgets-esm.js`;
|
|
46287
|
+
return cdnUrl;
|
|
46266
46288
|
}
|
|
46267
46289
|
|
|
46268
46290
|
const PUBLISHABLE_KEY_PREFIX = 'pk_imapik-';
|
|
@@ -46341,7 +46363,6 @@ const SANDBOX_CONFIGURATION = {
|
|
|
46341
46363
|
},
|
|
46342
46364
|
passport: undefined,
|
|
46343
46365
|
};
|
|
46344
|
-
const WIDGETS_SCRIPT_TIMEOUT = 100;
|
|
46345
46366
|
// Checkout SDK
|
|
46346
46367
|
class Checkout {
|
|
46347
46368
|
readOnlyProviders;
|
|
@@ -46371,26 +46392,44 @@ class Checkout {
|
|
|
46371
46392
|
const checkout = this;
|
|
46372
46393
|
// Preload the configurations
|
|
46373
46394
|
await checkout.config.remote.getConfig();
|
|
46395
|
+
try {
|
|
46396
|
+
const factory = await this.loadEsModules(init.config, init.version);
|
|
46397
|
+
return factory;
|
|
46398
|
+
}
|
|
46399
|
+
catch (err) {
|
|
46400
|
+
throw new CheckoutError('Failed to load widgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR, { error: err });
|
|
46401
|
+
}
|
|
46402
|
+
}
|
|
46403
|
+
async loadUmdBundle(config, version) {
|
|
46404
|
+
const checkout = this;
|
|
46374
46405
|
const factory = new Promise((resolve, reject) => {
|
|
46375
|
-
function checkForWidgetsBundleLoaded() {
|
|
46376
|
-
if (typeof ImmutableCheckoutWidgets !== 'undefined') {
|
|
46377
|
-
resolve(new ImmutableCheckoutWidgets.WidgetsFactory(checkout, init.config));
|
|
46378
|
-
}
|
|
46379
|
-
else {
|
|
46380
|
-
// If ImmutableCheckoutWidgets is not defined, wait for set amount of time.
|
|
46381
|
-
// When time has elapsed, check again if ImmutableCheckoutWidgets is defined.
|
|
46382
|
-
// Once it's defined, the promise will resolve and setTimeout won't be called again.
|
|
46383
|
-
setTimeout(checkForWidgetsBundleLoaded, WIDGETS_SCRIPT_TIMEOUT);
|
|
46384
|
-
}
|
|
46385
|
-
}
|
|
46386
46406
|
try {
|
|
46387
|
-
const
|
|
46388
|
-
|
|
46389
|
-
|
|
46390
|
-
|
|
46391
|
-
|
|
46392
|
-
|
|
46407
|
+
const scriptId = 'immutable-checkout-widgets-bundle';
|
|
46408
|
+
const validVersion = validateAndBuildVersion(version);
|
|
46409
|
+
// Prevent the script to be loaded more than once
|
|
46410
|
+
// by checking the presence of the script and its version.
|
|
46411
|
+
const initScript = document.getElementById(scriptId);
|
|
46412
|
+
if (initScript) {
|
|
46413
|
+
if (typeof ImmutableCheckoutWidgets !== 'undefined') {
|
|
46414
|
+
resolve(new ImmutableCheckoutWidgets.WidgetsFactory(checkout, config));
|
|
46415
|
+
}
|
|
46416
|
+
else {
|
|
46417
|
+
reject(new CheckoutError('Failed to find ImmutableCheckoutWidgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR));
|
|
46418
|
+
}
|
|
46393
46419
|
}
|
|
46420
|
+
const tag = document.createElement('script');
|
|
46421
|
+
tag.addEventListener('load', () => {
|
|
46422
|
+
if (typeof ImmutableCheckoutWidgets !== 'undefined') {
|
|
46423
|
+
resolve(new ImmutableCheckoutWidgets.WidgetsFactory(checkout, config));
|
|
46424
|
+
}
|
|
46425
|
+
else {
|
|
46426
|
+
reject(new CheckoutError('Failed to find ImmutableCheckoutWidgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR));
|
|
46427
|
+
}
|
|
46428
|
+
});
|
|
46429
|
+
tag.addEventListener('error', (err) => {
|
|
46430
|
+
reject(new CheckoutError('Failed to load widgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR, { error: err }));
|
|
46431
|
+
});
|
|
46432
|
+
loadUnresolvedBundle(tag, scriptId, validVersion);
|
|
46394
46433
|
}
|
|
46395
46434
|
catch (err) {
|
|
46396
46435
|
reject(new CheckoutError('Failed to load widgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR, { error: err }));
|
|
@@ -46398,6 +46437,24 @@ class Checkout {
|
|
|
46398
46437
|
});
|
|
46399
46438
|
return factory;
|
|
46400
46439
|
}
|
|
46440
|
+
async loadEsModules(config, version) {
|
|
46441
|
+
const checkout = this;
|
|
46442
|
+
try {
|
|
46443
|
+
const cdnUrl = getWidgetsEsmUrl(version);
|
|
46444
|
+
// WebpackIgnore comment required to prevent webpack modifying the import statement and
|
|
46445
|
+
// breaking the dynamic import in certain applications integrating checkout
|
|
46446
|
+
const checkoutWidgetsModule = await import(/* webpackIgnore: true */ cdnUrl);
|
|
46447
|
+
if (checkoutWidgetsModule && checkoutWidgetsModule.WidgetsFactory) {
|
|
46448
|
+
return new checkoutWidgetsModule.WidgetsFactory(checkout, config);
|
|
46449
|
+
}
|
|
46450
|
+
}
|
|
46451
|
+
catch (err) {
|
|
46452
|
+
// eslint-disable-next-line no-console
|
|
46453
|
+
console.warn(`Failed to resolve checkout widgets module, falling back to UMD bundle. Error: ${err.message}`);
|
|
46454
|
+
}
|
|
46455
|
+
// Fallback to UMD bundle if esm bundle fails to load
|
|
46456
|
+
return await checkout.loadUmdBundle(config, version);
|
|
46457
|
+
}
|
|
46401
46458
|
/**
|
|
46402
46459
|
* Creates a provider using the given parameters.
|
|
46403
46460
|
* @param {CreateProviderParams} params - The parameters for creating the provider.
|