@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.js
CHANGED
|
@@ -152,7 +152,7 @@ const flattenProperties$1 = (properties) => {
|
|
|
152
152
|
};
|
|
153
153
|
|
|
154
154
|
// WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
|
|
155
|
-
const SDK_VERSION$1 = '1.7.2';
|
|
155
|
+
const SDK_VERSION$1 = '1.7.3-alpha.2';
|
|
156
156
|
const getReferrer$1 = () => {
|
|
157
157
|
if (isNode$1()) {
|
|
158
158
|
return '';
|
|
@@ -11276,7 +11276,7 @@ class MultiRollupApiClients {
|
|
|
11276
11276
|
}
|
|
11277
11277
|
|
|
11278
11278
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
11279
|
-
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.7.2' };
|
|
11279
|
+
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.7.3-alpha.2' };
|
|
11280
11280
|
const createConfig = ({ basePath, headers, }) => {
|
|
11281
11281
|
if (!basePath.trim()) {
|
|
11282
11282
|
throw Error('basePath can not be empty');
|
|
@@ -11348,7 +11348,7 @@ class APIError extends Error {
|
|
|
11348
11348
|
|
|
11349
11349
|
/* eslint-disable implicit-arrow-linebreak */
|
|
11350
11350
|
const defaultHeaders = {
|
|
11351
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.7.2',
|
|
11351
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.7.3-alpha.2',
|
|
11352
11352
|
};
|
|
11353
11353
|
/**
|
|
11354
11354
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -11781,7 +11781,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
11781
11781
|
chainID,
|
|
11782
11782
|
coreContractAddress,
|
|
11783
11783
|
registrationContractAddress,
|
|
11784
|
-
sdkVersion: 'ts-immutable-sdk-1.7.2',
|
|
11784
|
+
sdkVersion: 'ts-immutable-sdk-1.7.3-alpha.2',
|
|
11785
11785
|
});
|
|
11786
11786
|
/**
|
|
11787
11787
|
* Sets `sdkVersion` at the time of build
|
|
@@ -16428,7 +16428,6 @@ const getAuthConfiguration = (config) => {
|
|
|
16428
16428
|
end_session_endpoint: endSessionEndpoint,
|
|
16429
16429
|
},
|
|
16430
16430
|
mergeClaims: true,
|
|
16431
|
-
loadUserInfo: true,
|
|
16432
16431
|
scope: oidcConfiguration.scope,
|
|
16433
16432
|
userStore,
|
|
16434
16433
|
};
|
|
@@ -16469,7 +16468,10 @@ class AuthManager {
|
|
|
16469
16468
|
this.logoutMode = config.oidcConfiguration.logoutMode || 'redirect';
|
|
16470
16469
|
}
|
|
16471
16470
|
static mapOidcUserToDomainModel = (oidcUser) => {
|
|
16472
|
-
|
|
16471
|
+
let passport;
|
|
16472
|
+
if (oidcUser.id_token) {
|
|
16473
|
+
passport = jwt_decode(oidcUser.id_token)?.passport;
|
|
16474
|
+
}
|
|
16473
16475
|
const user = {
|
|
16474
16476
|
expired: oidcUser.expired,
|
|
16475
16477
|
idToken: oidcUser.id_token,
|
|
@@ -17894,9 +17896,7 @@ class JsonRpcError extends Error {
|
|
|
17894
17896
|
}
|
|
17895
17897
|
|
|
17896
17898
|
const MESSAGE_TO_SIGN = 'Only sign this message from Immutable Passport';
|
|
17897
|
-
async function registerZkEvmUser({ authManager,
|
|
17898
|
-
const web3Provider = new Web3Provider(magicProvider);
|
|
17899
|
-
const ethSigner = web3Provider.getSigner();
|
|
17899
|
+
async function registerZkEvmUser({ authManager, ethSigner, multiRollupApiClients, accessToken, jsonRpcProvider, }) {
|
|
17900
17900
|
const ethereumAddress = await ethSigner.getAddress();
|
|
17901
17901
|
const ethereumSignature = await signRaw(MESSAGE_TO_SIGN, ethSigner);
|
|
17902
17902
|
const headers = { Authorization: `Bearer ${accessToken}` };
|
|
@@ -17926,32 +17926,6 @@ async function registerZkEvmUser({ authManager, magicProvider, multiRollupApiCli
|
|
|
17926
17926
|
return user;
|
|
17927
17927
|
}
|
|
17928
17928
|
|
|
17929
|
-
const loginZkEvmUser = async ({ authManager, magicAdapter, multiRollupApiClients, jsonRpcProvider, }) => {
|
|
17930
|
-
const user = await authManager.getUserOrLogin();
|
|
17931
|
-
if (!user.idToken) {
|
|
17932
|
-
throw new Error('User is missing idToken');
|
|
17933
|
-
}
|
|
17934
|
-
const magicProvider = await magicAdapter.login(user.idToken);
|
|
17935
|
-
if (!user.zkEvm) {
|
|
17936
|
-
// Generate counterfactual address and retrieve updated Auth0 user
|
|
17937
|
-
const userZkevm = await registerZkEvmUser({
|
|
17938
|
-
authManager,
|
|
17939
|
-
magicProvider,
|
|
17940
|
-
multiRollupApiClients,
|
|
17941
|
-
accessToken: user.accessToken,
|
|
17942
|
-
jsonRpcProvider,
|
|
17943
|
-
});
|
|
17944
|
-
return {
|
|
17945
|
-
user: userZkevm,
|
|
17946
|
-
magicProvider,
|
|
17947
|
-
};
|
|
17948
|
-
}
|
|
17949
|
-
return {
|
|
17950
|
-
user: user,
|
|
17951
|
-
magicProvider,
|
|
17952
|
-
};
|
|
17953
|
-
};
|
|
17954
|
-
|
|
17955
17929
|
const transactionRejectedCrossSdkBridgeError = 'Transaction requires confirmation but this functionality is not'
|
|
17956
17930
|
+ ' supported in this environment. Please contact Immutable support if you need to enable this feature.';
|
|
17957
17931
|
const convertBigNumberishToString = (value) => BigNumber$1.from(value).toString();
|
|
@@ -18147,7 +18121,7 @@ const getMetaTransactions = async (metaTransaction, nonce, chainId, walletAddres
|
|
|
18147
18121
|
}
|
|
18148
18122
|
return [metaTransaction, feeMetaTransaction];
|
|
18149
18123
|
};
|
|
18150
|
-
const sendTransaction$1 = ({ params,
|
|
18124
|
+
const sendTransaction$1 = ({ params, ethSigner, jsonRpcProvider, relayerClient, guardianClient, zkevmAddress, }) => guardianClient
|
|
18151
18125
|
.withConfirmationScreen({ width: 480, height: 720 })(async () => {
|
|
18152
18126
|
const transactionRequest = params[0];
|
|
18153
18127
|
if (!transactionRequest.to) {
|
|
@@ -18155,8 +18129,6 @@ const sendTransaction$1 = ({ params, magicProvider, jsonRpcProvider, relayerClie
|
|
|
18155
18129
|
}
|
|
18156
18130
|
const { chainId } = await jsonRpcProvider.ready;
|
|
18157
18131
|
const chainIdBigNumber = BigNumber$1.from(chainId);
|
|
18158
|
-
const magicWeb3Provider = new Web3Provider(magicProvider);
|
|
18159
|
-
const signer = magicWeb3Provider.getSigner();
|
|
18160
18132
|
const nonce = await getNonce(jsonRpcProvider, zkevmAddress);
|
|
18161
18133
|
const metaTransaction = {
|
|
18162
18134
|
to: transactionRequest.to,
|
|
@@ -18165,7 +18137,7 @@ const sendTransaction$1 = ({ params, magicProvider, jsonRpcProvider, relayerClie
|
|
|
18165
18137
|
value: transactionRequest.value,
|
|
18166
18138
|
revertOnError: true,
|
|
18167
18139
|
};
|
|
18168
|
-
const metaTransactions = await getMetaTransactions(metaTransaction, nonce, chainIdBigNumber, zkevmAddress,
|
|
18140
|
+
const metaTransactions = await getMetaTransactions(metaTransaction, nonce, chainIdBigNumber, zkevmAddress, ethSigner, relayerClient);
|
|
18169
18141
|
await guardianClient.validateEVMTransaction({
|
|
18170
18142
|
chainId: getEip155ChainId(chainId),
|
|
18171
18143
|
nonce: convertBigNumberishToString(nonce),
|
|
@@ -18173,7 +18145,7 @@ const sendTransaction$1 = ({ params, magicProvider, jsonRpcProvider, relayerClie
|
|
|
18173
18145
|
});
|
|
18174
18146
|
// NOTE: We sign again because we now are adding the fee transaction, so the
|
|
18175
18147
|
// whole payload is different and needs a new signature.
|
|
18176
|
-
const signedTransactions = await getSignedMetaTransactions(metaTransactions, nonce, chainIdBigNumber, zkevmAddress,
|
|
18148
|
+
const signedTransactions = await getSignedMetaTransactions(metaTransactions, nonce, chainIdBigNumber, zkevmAddress, ethSigner);
|
|
18177
18149
|
const relayerId = await relayerClient.ethSendTransaction(zkevmAddress, signedTransactions);
|
|
18178
18150
|
const retrieveRelayerTransaction = async () => {
|
|
18179
18151
|
const tx = await relayerClient.imGetTransactionByHash(relayerId);
|
|
@@ -18242,7 +18214,7 @@ const transformTypedData = (typedData, chainId) => {
|
|
|
18242
18214
|
}
|
|
18243
18215
|
return transformedTypedData;
|
|
18244
18216
|
};
|
|
18245
|
-
const signTypedDataV4 = async ({ params, method,
|
|
18217
|
+
const signTypedDataV4 = async ({ params, method, ethSigner, jsonRpcProvider, relayerClient, guardianClient, }) => guardianClient
|
|
18246
18218
|
.withConfirmationScreen({ width: 480, height: 720 })(async () => {
|
|
18247
18219
|
const fromAddress = params[0];
|
|
18248
18220
|
const typedDataParam = params[1];
|
|
@@ -18253,106 +18225,158 @@ const signTypedDataV4 = async ({ params, method, magicProvider, jsonRpcProvider,
|
|
|
18253
18225
|
const typedData = transformTypedData(typedDataParam, chainId);
|
|
18254
18226
|
await guardianClient.validateMessage({ chainID: String(chainId), payload: typedData });
|
|
18255
18227
|
const relayerSignature = await relayerClient.imSignTypedData(fromAddress, typedData);
|
|
18256
|
-
|
|
18257
|
-
const signer = magicWeb3Provider.getSigner();
|
|
18258
|
-
return getSignedTypedData(typedData, relayerSignature, BigNumber$1.from(chainId), fromAddress, signer);
|
|
18228
|
+
return getSignedTypedData(typedData, relayerSignature, BigNumber$1.from(chainId), fromAddress, ethSigner);
|
|
18259
18229
|
});
|
|
18260
18230
|
|
|
18231
|
+
const isZkEvmUser = (user) => 'zkEvm' in user;
|
|
18261
18232
|
class ZkEvmProvider {
|
|
18262
|
-
authManager;
|
|
18263
|
-
config;
|
|
18264
|
-
|
|
18265
|
-
|
|
18266
|
-
jsonRpcProvider; // Used for read
|
|
18267
|
-
|
|
18268
|
-
|
|
18269
|
-
relayerClient;
|
|
18270
|
-
|
|
18271
|
-
|
|
18233
|
+
#authManager;
|
|
18234
|
+
#config;
|
|
18235
|
+
#eventEmitter;
|
|
18236
|
+
#guardianClient;
|
|
18237
|
+
#jsonRpcProvider; // Used for read
|
|
18238
|
+
#magicAdapter;
|
|
18239
|
+
#multiRollupApiClients;
|
|
18240
|
+
#relayerClient;
|
|
18241
|
+
/**
|
|
18242
|
+
* This property is set during `#initialiseEthSigner` and stores the signer in a promise.
|
|
18243
|
+
* This property is not meant to be accessed directly, but through the
|
|
18244
|
+
* `#getSigner` method.
|
|
18245
|
+
* @see getSigner
|
|
18246
|
+
*/
|
|
18247
|
+
#ethSigner;
|
|
18248
|
+
#signerInitialisationError;
|
|
18249
|
+
#zkEvmAddress;
|
|
18272
18250
|
isPassport = true;
|
|
18273
18251
|
constructor({ authManager, magicAdapter, config, multiRollupApiClients, passportEventEmitter, guardianClient, }) {
|
|
18274
|
-
this
|
|
18275
|
-
this
|
|
18276
|
-
this
|
|
18277
|
-
this
|
|
18252
|
+
this.#authManager = authManager;
|
|
18253
|
+
this.#magicAdapter = magicAdapter;
|
|
18254
|
+
this.#config = config;
|
|
18255
|
+
this.#guardianClient = guardianClient;
|
|
18278
18256
|
if (config.crossSdkBridgeEnabled) {
|
|
18279
18257
|
// JsonRpcProvider by default sets the referrer as "client".
|
|
18280
18258
|
// On Unreal 4 this errors as the browser used is expecting a valid URL.
|
|
18281
|
-
this
|
|
18282
|
-
url: this
|
|
18259
|
+
this.#jsonRpcProvider = new JsonRpcProvider({
|
|
18260
|
+
url: this.#config.zkEvmRpcUrl,
|
|
18283
18261
|
fetchOptions: { referrer: 'http://imtblgamesdk.local' },
|
|
18284
18262
|
});
|
|
18285
18263
|
}
|
|
18286
18264
|
else {
|
|
18287
|
-
this
|
|
18265
|
+
this.#jsonRpcProvider = new JsonRpcProvider(this.#config.zkEvmRpcUrl);
|
|
18288
18266
|
}
|
|
18289
|
-
this
|
|
18290
|
-
|
|
18291
|
-
|
|
18292
|
-
|
|
18293
|
-
|
|
18294
|
-
|
|
18295
|
-
this
|
|
18296
|
-
|
|
18267
|
+
this.#relayerClient = new RelayerClient({
|
|
18268
|
+
config: this.#config,
|
|
18269
|
+
jsonRpcProvider: this.#jsonRpcProvider,
|
|
18270
|
+
authManager: this.#authManager,
|
|
18271
|
+
});
|
|
18272
|
+
this.#multiRollupApiClients = multiRollupApiClients;
|
|
18273
|
+
this.#eventEmitter = new TypedEventEmitter();
|
|
18274
|
+
passportEventEmitter.on(PassportEvents.LOGGED_OUT, this.#handleLogout);
|
|
18275
|
+
}
|
|
18276
|
+
#handleLogout = () => {
|
|
18277
|
+
const shouldEmitAccountsChanged = !!this.#zkEvmAddress;
|
|
18278
|
+
this.#ethSigner = undefined;
|
|
18279
|
+
this.#zkEvmAddress = undefined;
|
|
18297
18280
|
if (shouldEmitAccountsChanged) {
|
|
18298
|
-
this
|
|
18281
|
+
this.#eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, []);
|
|
18299
18282
|
}
|
|
18300
18283
|
};
|
|
18301
|
-
|
|
18302
|
-
|
|
18303
|
-
|
|
18304
|
-
|
|
18284
|
+
/**
|
|
18285
|
+
* This method is called by `eth_requestAccounts` and asynchronously initialises the signer.
|
|
18286
|
+
* The signer is stored in a promise so that it can be retrieved by the provider
|
|
18287
|
+
* when needed.
|
|
18288
|
+
*
|
|
18289
|
+
* If an error is thrown during initialisation, it is stored in the `signerInitialisationError`,
|
|
18290
|
+
* so that it doesn't result in an unhandled promise rejection.
|
|
18291
|
+
*
|
|
18292
|
+
* This error is thrown when the signer is requested through:
|
|
18293
|
+
* @see #getSigner
|
|
18294
|
+
*
|
|
18295
|
+
*/
|
|
18296
|
+
async #initialiseEthSigner(user) {
|
|
18297
|
+
const generateSigner = async () => {
|
|
18298
|
+
const magicRpcProvider = await this.#magicAdapter.login(user.idToken);
|
|
18299
|
+
const web3Provider = new Web3Provider(magicRpcProvider);
|
|
18300
|
+
return web3Provider.getSigner();
|
|
18301
|
+
};
|
|
18302
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
18303
|
+
this.#ethSigner = new Promise(async (resolve) => {
|
|
18304
|
+
try {
|
|
18305
|
+
resolve(await generateSigner());
|
|
18306
|
+
}
|
|
18307
|
+
catch (err) {
|
|
18308
|
+
// Capture and store the initialization error
|
|
18309
|
+
this.#signerInitialisationError = err;
|
|
18310
|
+
resolve(undefined);
|
|
18311
|
+
}
|
|
18312
|
+
});
|
|
18305
18313
|
}
|
|
18306
|
-
async
|
|
18314
|
+
async #getSigner() {
|
|
18315
|
+
const ethSigner = await this.#ethSigner;
|
|
18316
|
+
// Throw the stored error if the signers failed to initialise
|
|
18317
|
+
if (typeof ethSigner === 'undefined') {
|
|
18318
|
+
if (typeof this.#signerInitialisationError !== 'undefined') {
|
|
18319
|
+
throw this.#signerInitialisationError;
|
|
18320
|
+
}
|
|
18321
|
+
throw new Error('Signer failed to initialise');
|
|
18322
|
+
}
|
|
18323
|
+
return ethSigner;
|
|
18324
|
+
}
|
|
18325
|
+
async #performRequest(request) {
|
|
18307
18326
|
switch (request.method) {
|
|
18308
18327
|
case 'eth_requestAccounts': {
|
|
18309
|
-
if (this
|
|
18310
|
-
return [this
|
|
18328
|
+
if (this.#zkEvmAddress) {
|
|
18329
|
+
return [this.#zkEvmAddress];
|
|
18311
18330
|
}
|
|
18312
|
-
const
|
|
18313
|
-
|
|
18314
|
-
|
|
18315
|
-
|
|
18316
|
-
|
|
18317
|
-
|
|
18318
|
-
|
|
18319
|
-
|
|
18320
|
-
|
|
18321
|
-
|
|
18322
|
-
|
|
18323
|
-
|
|
18324
|
-
|
|
18325
|
-
|
|
18326
|
-
|
|
18331
|
+
const user = await this.#authManager.getUserOrLogin();
|
|
18332
|
+
this.#initialiseEthSigner(user);
|
|
18333
|
+
if (!isZkEvmUser(user)) {
|
|
18334
|
+
const ethSigner = await this.#getSigner();
|
|
18335
|
+
const userZkEvm = await registerZkEvmUser({
|
|
18336
|
+
ethSigner,
|
|
18337
|
+
authManager: this.#authManager,
|
|
18338
|
+
multiRollupApiClients: this.#multiRollupApiClients,
|
|
18339
|
+
accessToken: user.accessToken,
|
|
18340
|
+
jsonRpcProvider: this.#jsonRpcProvider,
|
|
18341
|
+
});
|
|
18342
|
+
this.#zkEvmAddress = userZkEvm.zkEvm.ethAddress;
|
|
18343
|
+
}
|
|
18344
|
+
else {
|
|
18345
|
+
this.#zkEvmAddress = user.zkEvm.ethAddress;
|
|
18346
|
+
}
|
|
18347
|
+
this.#eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, [this.#zkEvmAddress]);
|
|
18348
|
+
return [this.#zkEvmAddress];
|
|
18327
18349
|
}
|
|
18328
18350
|
case 'eth_sendTransaction': {
|
|
18329
|
-
if (!this
|
|
18351
|
+
if (!this.#zkEvmAddress) {
|
|
18330
18352
|
throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorised - call eth_requestAccounts first');
|
|
18331
18353
|
}
|
|
18354
|
+
const ethSigner = await this.#getSigner();
|
|
18332
18355
|
return sendTransaction$1({
|
|
18333
18356
|
params: request.params || [],
|
|
18334
|
-
|
|
18335
|
-
guardianClient: this
|
|
18336
|
-
jsonRpcProvider: this
|
|
18337
|
-
relayerClient: this
|
|
18338
|
-
zkevmAddress: this
|
|
18357
|
+
ethSigner,
|
|
18358
|
+
guardianClient: this.#guardianClient,
|
|
18359
|
+
jsonRpcProvider: this.#jsonRpcProvider,
|
|
18360
|
+
relayerClient: this.#relayerClient,
|
|
18361
|
+
zkevmAddress: this.#zkEvmAddress,
|
|
18339
18362
|
});
|
|
18340
18363
|
}
|
|
18341
18364
|
case 'eth_accounts': {
|
|
18342
|
-
return this
|
|
18365
|
+
return this.#zkEvmAddress ? [this.#zkEvmAddress] : [];
|
|
18343
18366
|
}
|
|
18344
18367
|
case 'eth_signTypedData':
|
|
18345
18368
|
case 'eth_signTypedData_v4': {
|
|
18346
|
-
if (!this
|
|
18369
|
+
if (!this.#zkEvmAddress) {
|
|
18347
18370
|
throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorised - call eth_requestAccounts first');
|
|
18348
18371
|
}
|
|
18372
|
+
const ethSigner = await this.#getSigner();
|
|
18349
18373
|
return signTypedDataV4({
|
|
18350
18374
|
method: request.method,
|
|
18351
18375
|
params: request.params || [],
|
|
18352
|
-
|
|
18353
|
-
jsonRpcProvider: this
|
|
18354
|
-
relayerClient: this
|
|
18355
|
-
guardianClient: this
|
|
18376
|
+
ethSigner,
|
|
18377
|
+
jsonRpcProvider: this.#jsonRpcProvider,
|
|
18378
|
+
relayerClient: this.#relayerClient,
|
|
18379
|
+
guardianClient: this.#guardianClient,
|
|
18356
18380
|
});
|
|
18357
18381
|
}
|
|
18358
18382
|
// Pass through methods
|
|
@@ -18369,17 +18393,17 @@ class ZkEvmProvider {
|
|
|
18369
18393
|
case 'eth_getTransactionByHash':
|
|
18370
18394
|
case 'eth_getTransactionReceipt':
|
|
18371
18395
|
case 'eth_getTransactionCount': {
|
|
18372
|
-
return this
|
|
18396
|
+
return this.#jsonRpcProvider.send(request.method, request.params || []);
|
|
18373
18397
|
}
|
|
18374
18398
|
default: {
|
|
18375
18399
|
throw new JsonRpcError(ProviderErrorCode.UNSUPPORTED_METHOD, 'Method not supported');
|
|
18376
18400
|
}
|
|
18377
18401
|
}
|
|
18378
18402
|
}
|
|
18379
|
-
async performJsonRpcRequest(request) {
|
|
18403
|
+
async #performJsonRpcRequest(request) {
|
|
18380
18404
|
const { id, jsonrpc } = request;
|
|
18381
18405
|
try {
|
|
18382
|
-
const result = await this
|
|
18406
|
+
const result = await this.#performRequest(request);
|
|
18383
18407
|
return {
|
|
18384
18408
|
id,
|
|
18385
18409
|
jsonrpc,
|
|
@@ -18406,7 +18430,7 @@ class ZkEvmProvider {
|
|
|
18406
18430
|
}
|
|
18407
18431
|
async request(request) {
|
|
18408
18432
|
try {
|
|
18409
|
-
return this
|
|
18433
|
+
return this.#performRequest(request);
|
|
18410
18434
|
}
|
|
18411
18435
|
catch (error) {
|
|
18412
18436
|
if (error instanceof JsonRpcError) {
|
|
@@ -18423,14 +18447,14 @@ class ZkEvmProvider {
|
|
|
18423
18447
|
throw new Error('No callback provided');
|
|
18424
18448
|
}
|
|
18425
18449
|
if (Array.isArray(request)) {
|
|
18426
|
-
Promise.all(request.map(this
|
|
18450
|
+
Promise.all(request.map(this.#performJsonRpcRequest)).then((result) => {
|
|
18427
18451
|
callback(null, result);
|
|
18428
18452
|
}).catch((error) => {
|
|
18429
18453
|
callback(error, []);
|
|
18430
18454
|
});
|
|
18431
18455
|
}
|
|
18432
18456
|
else {
|
|
18433
|
-
this
|
|
18457
|
+
this.#performJsonRpcRequest(request).then((result) => {
|
|
18434
18458
|
callback(null, result);
|
|
18435
18459
|
}).catch((error) => {
|
|
18436
18460
|
callback(error, null);
|
|
@@ -18462,15 +18486,15 @@ class ZkEvmProvider {
|
|
|
18462
18486
|
return this.sendAsync(request, callbackOrParams);
|
|
18463
18487
|
}
|
|
18464
18488
|
if (!Array.isArray(request) && typeof request === 'object') {
|
|
18465
|
-
return this
|
|
18489
|
+
return this.#performJsonRpcRequest(request);
|
|
18466
18490
|
}
|
|
18467
18491
|
throw new JsonRpcError(RpcErrorCode.INVALID_REQUEST, 'Invalid request');
|
|
18468
18492
|
}
|
|
18469
18493
|
on(event, listener) {
|
|
18470
|
-
this
|
|
18494
|
+
this.#eventEmitter.on(event, listener);
|
|
18471
18495
|
}
|
|
18472
18496
|
removeListener(event, listener) {
|
|
18473
|
-
this
|
|
18497
|
+
this.#eventEmitter.removeListener(event, listener);
|
|
18474
18498
|
}
|
|
18475
18499
|
}
|
|
18476
18500
|
|
|
@@ -37432,7 +37456,7 @@ const flattenProperties = (properties) => {
|
|
|
37432
37456
|
};
|
|
37433
37457
|
|
|
37434
37458
|
// WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
|
|
37435
|
-
const SDK_VERSION = '1.7.2';
|
|
37459
|
+
const SDK_VERSION = '1.7.3-alpha.2';
|
|
37436
37460
|
const getReferrer = () => {
|
|
37437
37461
|
if (isNode()) {
|
|
37438
37462
|
return '';
|
|
@@ -42600,7 +42624,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
|
|
|
42600
42624
|
maxPriorityFeePerGas: BigNumber$1.from(10e9),
|
|
42601
42625
|
};
|
|
42602
42626
|
|
|
42603
|
-
const SDK_VERSION_MARKER = '1.7.2';
|
|
42627
|
+
const SDK_VERSION_MARKER = '1.7.3-alpha.2';
|
|
42604
42628
|
// This SDK version is replaced by the `yarn build` command ran on the root level
|
|
42605
42629
|
const globalPackageVersion = () => SDK_VERSION_MARKER;
|
|
42606
42630
|
|
|
@@ -46220,27 +46244,25 @@ function validateAndBuildVersion(version) {
|
|
|
46220
46244
|
return validatedVersion;
|
|
46221
46245
|
}
|
|
46222
46246
|
|
|
46223
|
-
|
|
46247
|
+
// Loads the checkout widgets bundle from the CDN and appends the script to the document head
|
|
46248
|
+
function loadUnresolvedBundle(tag, scriptId, validVersion) {
|
|
46224
46249
|
if (window === undefined) {
|
|
46225
46250
|
throw new Error('missing window object: please run Checkout client side');
|
|
46226
46251
|
}
|
|
46227
46252
|
if (document === undefined) {
|
|
46228
46253
|
throw new Error('missing document object: please run Checkout client side');
|
|
46229
46254
|
}
|
|
46230
|
-
const scriptId = 'immutable-checkout-widgets-bundle';
|
|
46231
|
-
const validVersion = validateAndBuildVersion(version);
|
|
46232
|
-
// Prevent the script to be loaded more than once
|
|
46233
|
-
// by checking the presence of the script and its version.
|
|
46234
|
-
const initScript = document.getElementById(scriptId);
|
|
46235
|
-
if (initScript)
|
|
46236
|
-
return { loaded: true, element: initScript };
|
|
46237
|
-
const tag = document.createElement('script');
|
|
46238
46255
|
let cdnUrl = `https://cdn.jsdelivr.net/npm/@imtbl/sdk@${validVersion}/dist/browser/checkout/widgets.js`;
|
|
46239
46256
|
tag.setAttribute('id', scriptId);
|
|
46240
46257
|
tag.setAttribute('data-version', validVersion);
|
|
46241
46258
|
tag.setAttribute('src', cdnUrl);
|
|
46242
46259
|
document.head.appendChild(tag);
|
|
46243
|
-
|
|
46260
|
+
}
|
|
46261
|
+
// Gets the CDN url for the split checkout widgets bundle
|
|
46262
|
+
function getWidgetsEsmUrl(version) {
|
|
46263
|
+
const validVersion = validateAndBuildVersion(version);
|
|
46264
|
+
let cdnUrl = `https://cdn.jsdelivr.net/npm/@imtbl/sdk@${validVersion}/dist/browser/checkout/widgets-esm.js`;
|
|
46265
|
+
return cdnUrl;
|
|
46244
46266
|
}
|
|
46245
46267
|
|
|
46246
46268
|
const PUBLISHABLE_KEY_PREFIX = 'pk_imapik-';
|
|
@@ -46319,7 +46341,6 @@ const SANDBOX_CONFIGURATION = {
|
|
|
46319
46341
|
},
|
|
46320
46342
|
passport: undefined,
|
|
46321
46343
|
};
|
|
46322
|
-
const WIDGETS_SCRIPT_TIMEOUT = 100;
|
|
46323
46344
|
// Checkout SDK
|
|
46324
46345
|
class Checkout {
|
|
46325
46346
|
readOnlyProviders;
|
|
@@ -46349,26 +46370,44 @@ class Checkout {
|
|
|
46349
46370
|
const checkout = this;
|
|
46350
46371
|
// Preload the configurations
|
|
46351
46372
|
await checkout.config.remote.getConfig();
|
|
46373
|
+
try {
|
|
46374
|
+
const factory = await this.loadEsModules(init.config, init.version);
|
|
46375
|
+
return factory;
|
|
46376
|
+
}
|
|
46377
|
+
catch (err) {
|
|
46378
|
+
throw new CheckoutError('Failed to load widgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR, { error: err });
|
|
46379
|
+
}
|
|
46380
|
+
}
|
|
46381
|
+
async loadUmdBundle(config, version) {
|
|
46382
|
+
const checkout = this;
|
|
46352
46383
|
const factory = new Promise((resolve, reject) => {
|
|
46353
|
-
function checkForWidgetsBundleLoaded() {
|
|
46354
|
-
if (typeof ImmutableCheckoutWidgets !== 'undefined') {
|
|
46355
|
-
resolve(new ImmutableCheckoutWidgets.WidgetsFactory(checkout, init.config));
|
|
46356
|
-
}
|
|
46357
|
-
else {
|
|
46358
|
-
// If ImmutableCheckoutWidgets is not defined, wait for set amount of time.
|
|
46359
|
-
// When time has elapsed, check again if ImmutableCheckoutWidgets is defined.
|
|
46360
|
-
// Once it's defined, the promise will resolve and setTimeout won't be called again.
|
|
46361
|
-
setTimeout(checkForWidgetsBundleLoaded, WIDGETS_SCRIPT_TIMEOUT);
|
|
46362
|
-
}
|
|
46363
|
-
}
|
|
46364
46384
|
try {
|
|
46365
|
-
const
|
|
46366
|
-
|
|
46367
|
-
|
|
46368
|
-
|
|
46369
|
-
|
|
46370
|
-
|
|
46385
|
+
const scriptId = 'immutable-checkout-widgets-bundle';
|
|
46386
|
+
const validVersion = validateAndBuildVersion(version);
|
|
46387
|
+
// Prevent the script to be loaded more than once
|
|
46388
|
+
// by checking the presence of the script and its version.
|
|
46389
|
+
const initScript = document.getElementById(scriptId);
|
|
46390
|
+
if (initScript) {
|
|
46391
|
+
if (typeof ImmutableCheckoutWidgets !== 'undefined') {
|
|
46392
|
+
resolve(new ImmutableCheckoutWidgets.WidgetsFactory(checkout, config));
|
|
46393
|
+
}
|
|
46394
|
+
else {
|
|
46395
|
+
reject(new CheckoutError('Failed to find ImmutableCheckoutWidgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR));
|
|
46396
|
+
}
|
|
46371
46397
|
}
|
|
46398
|
+
const tag = document.createElement('script');
|
|
46399
|
+
tag.addEventListener('load', () => {
|
|
46400
|
+
if (typeof ImmutableCheckoutWidgets !== 'undefined') {
|
|
46401
|
+
resolve(new ImmutableCheckoutWidgets.WidgetsFactory(checkout, config));
|
|
46402
|
+
}
|
|
46403
|
+
else {
|
|
46404
|
+
reject(new CheckoutError('Failed to find ImmutableCheckoutWidgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR));
|
|
46405
|
+
}
|
|
46406
|
+
});
|
|
46407
|
+
tag.addEventListener('error', (err) => {
|
|
46408
|
+
reject(new CheckoutError('Failed to load widgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR, { error: err }));
|
|
46409
|
+
});
|
|
46410
|
+
loadUnresolvedBundle(tag, scriptId, validVersion);
|
|
46372
46411
|
}
|
|
46373
46412
|
catch (err) {
|
|
46374
46413
|
reject(new CheckoutError('Failed to load widgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR, { error: err }));
|
|
@@ -46376,6 +46415,24 @@ class Checkout {
|
|
|
46376
46415
|
});
|
|
46377
46416
|
return factory;
|
|
46378
46417
|
}
|
|
46418
|
+
async loadEsModules(config, version) {
|
|
46419
|
+
const checkout = this;
|
|
46420
|
+
try {
|
|
46421
|
+
const cdnUrl = getWidgetsEsmUrl(version);
|
|
46422
|
+
// WebpackIgnore comment required to prevent webpack modifying the import statement and
|
|
46423
|
+
// breaking the dynamic import in certain applications integrating checkout
|
|
46424
|
+
const checkoutWidgetsModule = await import(/* webpackIgnore: true */ cdnUrl);
|
|
46425
|
+
if (checkoutWidgetsModule && checkoutWidgetsModule.WidgetsFactory) {
|
|
46426
|
+
return new checkoutWidgetsModule.WidgetsFactory(checkout, config);
|
|
46427
|
+
}
|
|
46428
|
+
}
|
|
46429
|
+
catch (err) {
|
|
46430
|
+
// eslint-disable-next-line no-console
|
|
46431
|
+
console.warn(`Failed to resolve checkout widgets module, falling back to UMD bundle. Error: ${err.message}`);
|
|
46432
|
+
}
|
|
46433
|
+
// Fallback to UMD bundle if esm bundle fails to load
|
|
46434
|
+
return await checkout.loadUmdBundle(config, version);
|
|
46435
|
+
}
|
|
46379
46436
|
/**
|
|
46380
46437
|
* Creates a provider using the given parameters.
|
|
46381
46438
|
* @param {CreateProviderParams} params - The parameters for creating the provider.
|
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.2';
|
|
134
|
+
const SDK_VERSION = '1.7.3-alpha.2';
|
|
135
135
|
const getReferrer = () => {
|
|
136
136
|
if (isNode()) {
|
|
137
137
|
return '';
|