@imtbl/sdk 1.7.3 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +224 -161
- package/dist/index.d.ts +3 -1
- package/dist/index.js +224 -161
- package/dist/orderbook.js +1 -1
- package/dist/passport.js +160 -130
- 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.
|
|
177
|
+
const SDK_VERSION$1 = '1.8.0';
|
|
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.
|
|
11301
|
+
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.8.0' };
|
|
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.
|
|
11373
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.8.0',
|
|
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.
|
|
11806
|
+
sdkVersion: 'ts-immutable-sdk-1.8.0',
|
|
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,27 +17918,28 @@ 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
|
|
17921
|
-
|
|
17922
|
-
|
|
17923
|
-
|
|
17924
|
-
|
|
17925
|
-
|
|
17926
|
-
const eipChainId = getEip155ChainId(chainId);
|
|
17921
|
+
async function registerZkEvmUser({ authManager, ethSigner, multiRollupApiClients, accessToken, jsonRpcProvider, }) {
|
|
17922
|
+
const [ethereumAddress, ethereumSignature, network, chainListResponse] = await Promise.all([
|
|
17923
|
+
ethSigner.getAddress(),
|
|
17924
|
+
signRaw(MESSAGE_TO_SIGN, ethSigner),
|
|
17925
|
+
jsonRpcProvider.ready,
|
|
17926
|
+
multiRollupApiClients.chainsApi.listChains(),
|
|
17927
|
+
]);
|
|
17928
|
+
const eipChainId = getEip155ChainId(network.chainId);
|
|
17929
|
+
const chainName = chainListResponse.data?.result?.find((chain) => chain.id === eipChainId)?.name;
|
|
17930
|
+
if (!chainName) {
|
|
17931
|
+
throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Chain name does not exist on for chain id ${network.chainId}`);
|
|
17932
|
+
}
|
|
17927
17933
|
try {
|
|
17928
|
-
const chainList = (await multiRollupApiClients.chainsApi.listChains()).data.result;
|
|
17929
|
-
const chainName = chainList.find((chain) => chain.id === eipChainId)?.name;
|
|
17930
|
-
if (!chainName) {
|
|
17931
|
-
throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Chain name does not exist on for chain id ${chainId}`);
|
|
17932
|
-
}
|
|
17933
17934
|
await multiRollupApiClients.passportApi.createCounterfactualAddressV2({
|
|
17934
17935
|
chainName,
|
|
17935
17936
|
createCounterfactualAddressRequest: {
|
|
17936
17937
|
ethereum_address: ethereumAddress,
|
|
17937
17938
|
ethereum_signature: ethereumSignature,
|
|
17938
17939
|
},
|
|
17939
|
-
}, {
|
|
17940
|
+
}, {
|
|
17941
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
17942
|
+
});
|
|
17940
17943
|
}
|
|
17941
17944
|
catch (error) {
|
|
17942
17945
|
throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Failed to create counterfactual address: ${error}`);
|
|
@@ -17948,32 +17951,6 @@ async function registerZkEvmUser({ authManager, magicProvider, multiRollupApiCli
|
|
|
17948
17951
|
return user;
|
|
17949
17952
|
}
|
|
17950
17953
|
|
|
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
17954
|
const transactionRejectedCrossSdkBridgeError = 'Transaction requires confirmation but this functionality is not'
|
|
17978
17955
|
+ ' supported in this environment. Please contact Immutable support if you need to enable this feature.';
|
|
17979
17956
|
const convertBigNumberishToString = (value) => ethers.BigNumber.from(value).toString();
|
|
@@ -18169,7 +18146,7 @@ const getMetaTransactions = async (metaTransaction, nonce, chainId, walletAddres
|
|
|
18169
18146
|
}
|
|
18170
18147
|
return [metaTransaction, feeMetaTransaction];
|
|
18171
18148
|
};
|
|
18172
|
-
const sendTransaction$1 = ({ params,
|
|
18149
|
+
const sendTransaction$1 = ({ params, ethSigner, jsonRpcProvider, relayerClient, guardianClient, zkevmAddress, }) => guardianClient
|
|
18173
18150
|
.withConfirmationScreen({ width: 480, height: 720 })(async () => {
|
|
18174
18151
|
const transactionRequest = params[0];
|
|
18175
18152
|
if (!transactionRequest.to) {
|
|
@@ -18177,8 +18154,6 @@ const sendTransaction$1 = ({ params, magicProvider, jsonRpcProvider, relayerClie
|
|
|
18177
18154
|
}
|
|
18178
18155
|
const { chainId } = await jsonRpcProvider.ready;
|
|
18179
18156
|
const chainIdBigNumber = ethers.BigNumber.from(chainId);
|
|
18180
|
-
const magicWeb3Provider = new providers.Web3Provider(magicProvider);
|
|
18181
|
-
const signer = magicWeb3Provider.getSigner();
|
|
18182
18157
|
const nonce = await getNonce(jsonRpcProvider, zkevmAddress);
|
|
18183
18158
|
const metaTransaction = {
|
|
18184
18159
|
to: transactionRequest.to,
|
|
@@ -18187,15 +18162,18 @@ const sendTransaction$1 = ({ params, magicProvider, jsonRpcProvider, relayerClie
|
|
|
18187
18162
|
value: transactionRequest.value,
|
|
18188
18163
|
revertOnError: true,
|
|
18189
18164
|
};
|
|
18190
|
-
const metaTransactions = await getMetaTransactions(metaTransaction, nonce, chainIdBigNumber, zkevmAddress,
|
|
18191
|
-
|
|
18192
|
-
|
|
18193
|
-
|
|
18194
|
-
|
|
18195
|
-
|
|
18196
|
-
|
|
18197
|
-
|
|
18198
|
-
|
|
18165
|
+
const metaTransactions = await getMetaTransactions(metaTransaction, nonce, chainIdBigNumber, zkevmAddress, ethSigner, relayerClient);
|
|
18166
|
+
// Parallelize the validation and signing of the transaction
|
|
18167
|
+
const [, signedTransactions] = await Promise.all([
|
|
18168
|
+
guardianClient.validateEVMTransaction({
|
|
18169
|
+
chainId: getEip155ChainId(chainId),
|
|
18170
|
+
nonce: convertBigNumberishToString(nonce),
|
|
18171
|
+
metaTransactions,
|
|
18172
|
+
}),
|
|
18173
|
+
// NOTE: We sign again because we now are adding the fee transaction, so the
|
|
18174
|
+
// whole payload is different and needs a new signature.
|
|
18175
|
+
getSignedMetaTransactions(metaTransactions, nonce, chainIdBigNumber, zkevmAddress, ethSigner),
|
|
18176
|
+
]);
|
|
18199
18177
|
const relayerId = await relayerClient.ethSendTransaction(zkevmAddress, signedTransactions);
|
|
18200
18178
|
const retrieveRelayerTransaction = async () => {
|
|
18201
18179
|
const tx = await relayerClient.imGetTransactionByHash(relayerId);
|
|
@@ -18264,7 +18242,7 @@ const transformTypedData = (typedData, chainId) => {
|
|
|
18264
18242
|
}
|
|
18265
18243
|
return transformedTypedData;
|
|
18266
18244
|
};
|
|
18267
|
-
const signTypedDataV4 = async ({ params, method,
|
|
18245
|
+
const signTypedDataV4 = async ({ params, method, ethSigner, jsonRpcProvider, relayerClient, guardianClient, }) => guardianClient
|
|
18268
18246
|
.withConfirmationScreen({ width: 480, height: 720 })(async () => {
|
|
18269
18247
|
const fromAddress = params[0];
|
|
18270
18248
|
const typedDataParam = params[1];
|
|
@@ -18275,106 +18253,158 @@ const signTypedDataV4 = async ({ params, method, magicProvider, jsonRpcProvider,
|
|
|
18275
18253
|
const typedData = transformTypedData(typedDataParam, chainId);
|
|
18276
18254
|
await guardianClient.validateMessage({ chainID: String(chainId), payload: typedData });
|
|
18277
18255
|
const relayerSignature = await relayerClient.imSignTypedData(fromAddress, typedData);
|
|
18278
|
-
|
|
18279
|
-
const signer = magicWeb3Provider.getSigner();
|
|
18280
|
-
return getSignedTypedData(typedData, relayerSignature, ethers.BigNumber.from(chainId), fromAddress, signer);
|
|
18256
|
+
return getSignedTypedData(typedData, relayerSignature, ethers.BigNumber.from(chainId), fromAddress, ethSigner);
|
|
18281
18257
|
});
|
|
18282
18258
|
|
|
18259
|
+
const isZkEvmUser = (user) => 'zkEvm' in user;
|
|
18283
18260
|
class ZkEvmProvider {
|
|
18284
|
-
authManager;
|
|
18285
|
-
config;
|
|
18286
|
-
|
|
18287
|
-
|
|
18288
|
-
jsonRpcProvider; // Used for read
|
|
18289
|
-
|
|
18290
|
-
|
|
18291
|
-
relayerClient;
|
|
18292
|
-
|
|
18293
|
-
|
|
18261
|
+
#authManager;
|
|
18262
|
+
#config;
|
|
18263
|
+
#eventEmitter;
|
|
18264
|
+
#guardianClient;
|
|
18265
|
+
#jsonRpcProvider; // Used for read
|
|
18266
|
+
#magicAdapter;
|
|
18267
|
+
#multiRollupApiClients;
|
|
18268
|
+
#relayerClient;
|
|
18269
|
+
/**
|
|
18270
|
+
* This property is set during `#initialiseEthSigner` and stores the signer in a promise.
|
|
18271
|
+
* This property is not meant to be accessed directly, but through the
|
|
18272
|
+
* `#getSigner` method.
|
|
18273
|
+
* @see getSigner
|
|
18274
|
+
*/
|
|
18275
|
+
#ethSigner;
|
|
18276
|
+
#signerInitialisationError;
|
|
18277
|
+
#zkEvmAddress;
|
|
18294
18278
|
isPassport = true;
|
|
18295
18279
|
constructor({ authManager, magicAdapter, config, multiRollupApiClients, passportEventEmitter, guardianClient, }) {
|
|
18296
|
-
this
|
|
18297
|
-
this
|
|
18298
|
-
this
|
|
18299
|
-
this
|
|
18280
|
+
this.#authManager = authManager;
|
|
18281
|
+
this.#magicAdapter = magicAdapter;
|
|
18282
|
+
this.#config = config;
|
|
18283
|
+
this.#guardianClient = guardianClient;
|
|
18300
18284
|
if (config.crossSdkBridgeEnabled) {
|
|
18301
18285
|
// JsonRpcProvider by default sets the referrer as "client".
|
|
18302
18286
|
// On Unreal 4 this errors as the browser used is expecting a valid URL.
|
|
18303
|
-
this
|
|
18304
|
-
url: this
|
|
18287
|
+
this.#jsonRpcProvider = new providers.JsonRpcProvider({
|
|
18288
|
+
url: this.#config.zkEvmRpcUrl,
|
|
18305
18289
|
fetchOptions: { referrer: 'http://imtblgamesdk.local' },
|
|
18306
18290
|
});
|
|
18307
18291
|
}
|
|
18308
18292
|
else {
|
|
18309
|
-
this
|
|
18293
|
+
this.#jsonRpcProvider = new providers.JsonRpcProvider(this.#config.zkEvmRpcUrl);
|
|
18310
18294
|
}
|
|
18311
|
-
this
|
|
18312
|
-
|
|
18313
|
-
|
|
18314
|
-
|
|
18315
|
-
|
|
18316
|
-
|
|
18317
|
-
this
|
|
18318
|
-
|
|
18295
|
+
this.#relayerClient = new RelayerClient({
|
|
18296
|
+
config: this.#config,
|
|
18297
|
+
jsonRpcProvider: this.#jsonRpcProvider,
|
|
18298
|
+
authManager: this.#authManager,
|
|
18299
|
+
});
|
|
18300
|
+
this.#multiRollupApiClients = multiRollupApiClients;
|
|
18301
|
+
this.#eventEmitter = new TypedEventEmitter();
|
|
18302
|
+
passportEventEmitter.on(PassportEvents.LOGGED_OUT, this.#handleLogout);
|
|
18303
|
+
}
|
|
18304
|
+
#handleLogout = () => {
|
|
18305
|
+
const shouldEmitAccountsChanged = !!this.#zkEvmAddress;
|
|
18306
|
+
this.#ethSigner = undefined;
|
|
18307
|
+
this.#zkEvmAddress = undefined;
|
|
18319
18308
|
if (shouldEmitAccountsChanged) {
|
|
18320
|
-
this
|
|
18309
|
+
this.#eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, []);
|
|
18321
18310
|
}
|
|
18322
18311
|
};
|
|
18323
|
-
|
|
18324
|
-
|
|
18325
|
-
|
|
18326
|
-
|
|
18312
|
+
/**
|
|
18313
|
+
* This method is called by `eth_requestAccounts` and asynchronously initialises the signer.
|
|
18314
|
+
* The signer is stored in a promise so that it can be retrieved by the provider
|
|
18315
|
+
* when needed.
|
|
18316
|
+
*
|
|
18317
|
+
* If an error is thrown during initialisation, it is stored in the `signerInitialisationError`,
|
|
18318
|
+
* so that it doesn't result in an unhandled promise rejection.
|
|
18319
|
+
*
|
|
18320
|
+
* This error is thrown when the signer is requested through:
|
|
18321
|
+
* @see #getSigner
|
|
18322
|
+
*
|
|
18323
|
+
*/
|
|
18324
|
+
async #initialiseEthSigner(user) {
|
|
18325
|
+
const generateSigner = async () => {
|
|
18326
|
+
const magicRpcProvider = await this.#magicAdapter.login(user.idToken);
|
|
18327
|
+
const web3Provider = new providers.Web3Provider(magicRpcProvider);
|
|
18328
|
+
return web3Provider.getSigner();
|
|
18329
|
+
};
|
|
18330
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
18331
|
+
this.#ethSigner = new Promise(async (resolve) => {
|
|
18332
|
+
try {
|
|
18333
|
+
resolve(await generateSigner());
|
|
18334
|
+
}
|
|
18335
|
+
catch (err) {
|
|
18336
|
+
// Capture and store the initialization error
|
|
18337
|
+
this.#signerInitialisationError = err;
|
|
18338
|
+
resolve(undefined);
|
|
18339
|
+
}
|
|
18340
|
+
});
|
|
18327
18341
|
}
|
|
18328
|
-
async
|
|
18342
|
+
async #getSigner() {
|
|
18343
|
+
const ethSigner = await this.#ethSigner;
|
|
18344
|
+
// Throw the stored error if the signers failed to initialise
|
|
18345
|
+
if (typeof ethSigner === 'undefined') {
|
|
18346
|
+
if (typeof this.#signerInitialisationError !== 'undefined') {
|
|
18347
|
+
throw this.#signerInitialisationError;
|
|
18348
|
+
}
|
|
18349
|
+
throw new Error('Signer failed to initialise');
|
|
18350
|
+
}
|
|
18351
|
+
return ethSigner;
|
|
18352
|
+
}
|
|
18353
|
+
async #performRequest(request) {
|
|
18329
18354
|
switch (request.method) {
|
|
18330
18355
|
case 'eth_requestAccounts': {
|
|
18331
|
-
if (this
|
|
18332
|
-
return [this
|
|
18356
|
+
if (this.#zkEvmAddress) {
|
|
18357
|
+
return [this.#zkEvmAddress];
|
|
18333
18358
|
}
|
|
18334
|
-
const
|
|
18335
|
-
|
|
18336
|
-
|
|
18337
|
-
|
|
18338
|
-
|
|
18339
|
-
|
|
18340
|
-
|
|
18341
|
-
|
|
18342
|
-
|
|
18343
|
-
|
|
18344
|
-
|
|
18345
|
-
|
|
18346
|
-
|
|
18347
|
-
|
|
18348
|
-
|
|
18359
|
+
const user = await this.#authManager.getUserOrLogin();
|
|
18360
|
+
this.#initialiseEthSigner(user);
|
|
18361
|
+
if (!isZkEvmUser(user)) {
|
|
18362
|
+
const ethSigner = await this.#getSigner();
|
|
18363
|
+
const userZkEvm = await registerZkEvmUser({
|
|
18364
|
+
ethSigner,
|
|
18365
|
+
authManager: this.#authManager,
|
|
18366
|
+
multiRollupApiClients: this.#multiRollupApiClients,
|
|
18367
|
+
accessToken: user.accessToken,
|
|
18368
|
+
jsonRpcProvider: this.#jsonRpcProvider,
|
|
18369
|
+
});
|
|
18370
|
+
this.#zkEvmAddress = userZkEvm.zkEvm.ethAddress;
|
|
18371
|
+
}
|
|
18372
|
+
else {
|
|
18373
|
+
this.#zkEvmAddress = user.zkEvm.ethAddress;
|
|
18374
|
+
}
|
|
18375
|
+
this.#eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, [this.#zkEvmAddress]);
|
|
18376
|
+
return [this.#zkEvmAddress];
|
|
18349
18377
|
}
|
|
18350
18378
|
case 'eth_sendTransaction': {
|
|
18351
|
-
if (!this
|
|
18379
|
+
if (!this.#zkEvmAddress) {
|
|
18352
18380
|
throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorised - call eth_requestAccounts first');
|
|
18353
18381
|
}
|
|
18382
|
+
const ethSigner = await this.#getSigner();
|
|
18354
18383
|
return sendTransaction$1({
|
|
18355
18384
|
params: request.params || [],
|
|
18356
|
-
|
|
18357
|
-
guardianClient: this
|
|
18358
|
-
jsonRpcProvider: this
|
|
18359
|
-
relayerClient: this
|
|
18360
|
-
zkevmAddress: this
|
|
18385
|
+
ethSigner,
|
|
18386
|
+
guardianClient: this.#guardianClient,
|
|
18387
|
+
jsonRpcProvider: this.#jsonRpcProvider,
|
|
18388
|
+
relayerClient: this.#relayerClient,
|
|
18389
|
+
zkevmAddress: this.#zkEvmAddress,
|
|
18361
18390
|
});
|
|
18362
18391
|
}
|
|
18363
18392
|
case 'eth_accounts': {
|
|
18364
|
-
return this
|
|
18393
|
+
return this.#zkEvmAddress ? [this.#zkEvmAddress] : [];
|
|
18365
18394
|
}
|
|
18366
18395
|
case 'eth_signTypedData':
|
|
18367
18396
|
case 'eth_signTypedData_v4': {
|
|
18368
|
-
if (!this
|
|
18397
|
+
if (!this.#zkEvmAddress) {
|
|
18369
18398
|
throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorised - call eth_requestAccounts first');
|
|
18370
18399
|
}
|
|
18400
|
+
const ethSigner = await this.#getSigner();
|
|
18371
18401
|
return signTypedDataV4({
|
|
18372
18402
|
method: request.method,
|
|
18373
18403
|
params: request.params || [],
|
|
18374
|
-
|
|
18375
|
-
jsonRpcProvider: this
|
|
18376
|
-
relayerClient: this
|
|
18377
|
-
guardianClient: this
|
|
18404
|
+
ethSigner,
|
|
18405
|
+
jsonRpcProvider: this.#jsonRpcProvider,
|
|
18406
|
+
relayerClient: this.#relayerClient,
|
|
18407
|
+
guardianClient: this.#guardianClient,
|
|
18378
18408
|
});
|
|
18379
18409
|
}
|
|
18380
18410
|
// Pass through methods
|
|
@@ -18391,17 +18421,17 @@ class ZkEvmProvider {
|
|
|
18391
18421
|
case 'eth_getTransactionByHash':
|
|
18392
18422
|
case 'eth_getTransactionReceipt':
|
|
18393
18423
|
case 'eth_getTransactionCount': {
|
|
18394
|
-
return this
|
|
18424
|
+
return this.#jsonRpcProvider.send(request.method, request.params || []);
|
|
18395
18425
|
}
|
|
18396
18426
|
default: {
|
|
18397
18427
|
throw new JsonRpcError(ProviderErrorCode.UNSUPPORTED_METHOD, 'Method not supported');
|
|
18398
18428
|
}
|
|
18399
18429
|
}
|
|
18400
18430
|
}
|
|
18401
|
-
async performJsonRpcRequest(request) {
|
|
18431
|
+
async #performJsonRpcRequest(request) {
|
|
18402
18432
|
const { id, jsonrpc } = request;
|
|
18403
18433
|
try {
|
|
18404
|
-
const result = await this
|
|
18434
|
+
const result = await this.#performRequest(request);
|
|
18405
18435
|
return {
|
|
18406
18436
|
id,
|
|
18407
18437
|
jsonrpc,
|
|
@@ -18428,7 +18458,7 @@ class ZkEvmProvider {
|
|
|
18428
18458
|
}
|
|
18429
18459
|
async request(request) {
|
|
18430
18460
|
try {
|
|
18431
|
-
return this
|
|
18461
|
+
return this.#performRequest(request);
|
|
18432
18462
|
}
|
|
18433
18463
|
catch (error) {
|
|
18434
18464
|
if (error instanceof JsonRpcError) {
|
|
@@ -18445,14 +18475,14 @@ class ZkEvmProvider {
|
|
|
18445
18475
|
throw new Error('No callback provided');
|
|
18446
18476
|
}
|
|
18447
18477
|
if (Array.isArray(request)) {
|
|
18448
|
-
Promise.all(request.map(this
|
|
18478
|
+
Promise.all(request.map(this.#performJsonRpcRequest)).then((result) => {
|
|
18449
18479
|
callback(null, result);
|
|
18450
18480
|
}).catch((error) => {
|
|
18451
18481
|
callback(error, []);
|
|
18452
18482
|
});
|
|
18453
18483
|
}
|
|
18454
18484
|
else {
|
|
18455
|
-
this
|
|
18485
|
+
this.#performJsonRpcRequest(request).then((result) => {
|
|
18456
18486
|
callback(null, result);
|
|
18457
18487
|
}).catch((error) => {
|
|
18458
18488
|
callback(error, null);
|
|
@@ -18484,15 +18514,15 @@ class ZkEvmProvider {
|
|
|
18484
18514
|
return this.sendAsync(request, callbackOrParams);
|
|
18485
18515
|
}
|
|
18486
18516
|
if (!Array.isArray(request) && typeof request === 'object') {
|
|
18487
|
-
return this
|
|
18517
|
+
return this.#performJsonRpcRequest(request);
|
|
18488
18518
|
}
|
|
18489
18519
|
throw new JsonRpcError(RpcErrorCode.INVALID_REQUEST, 'Invalid request');
|
|
18490
18520
|
}
|
|
18491
18521
|
on(event, listener) {
|
|
18492
|
-
this
|
|
18522
|
+
this.#eventEmitter.on(event, listener);
|
|
18493
18523
|
}
|
|
18494
18524
|
removeListener(event, listener) {
|
|
18495
|
-
this
|
|
18525
|
+
this.#eventEmitter.removeListener(event, listener);
|
|
18496
18526
|
}
|
|
18497
18527
|
}
|
|
18498
18528
|
|
|
@@ -37454,7 +37484,7 @@ const flattenProperties = (properties) => {
|
|
|
37454
37484
|
};
|
|
37455
37485
|
|
|
37456
37486
|
// WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
|
|
37457
|
-
const SDK_VERSION = '1.
|
|
37487
|
+
const SDK_VERSION = '1.8.0';
|
|
37458
37488
|
const getReferrer = () => {
|
|
37459
37489
|
if (isNode()) {
|
|
37460
37490
|
return '';
|
|
@@ -42622,7 +42652,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
|
|
|
42622
42652
|
maxPriorityFeePerGas: ethers.BigNumber.from(10e9),
|
|
42623
42653
|
};
|
|
42624
42654
|
|
|
42625
|
-
const SDK_VERSION_MARKER = '1.
|
|
42655
|
+
const SDK_VERSION_MARKER = '1.8.0';
|
|
42626
42656
|
// This SDK version is replaced by the `yarn build` command ran on the root level
|
|
42627
42657
|
const globalPackageVersion = () => SDK_VERSION_MARKER;
|
|
42628
42658
|
|
|
@@ -46242,27 +46272,25 @@ function validateAndBuildVersion(version) {
|
|
|
46242
46272
|
return validatedVersion;
|
|
46243
46273
|
}
|
|
46244
46274
|
|
|
46245
|
-
|
|
46275
|
+
// Loads the checkout widgets bundle from the CDN and appends the script to the document head
|
|
46276
|
+
function loadUnresolvedBundle(tag, scriptId, validVersion) {
|
|
46246
46277
|
if (window === undefined) {
|
|
46247
46278
|
throw new Error('missing window object: please run Checkout client side');
|
|
46248
46279
|
}
|
|
46249
46280
|
if (document === undefined) {
|
|
46250
46281
|
throw new Error('missing document object: please run Checkout client side');
|
|
46251
46282
|
}
|
|
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
46283
|
let cdnUrl = `https://cdn.jsdelivr.net/npm/@imtbl/sdk@${validVersion}/dist/browser/checkout/widgets.js`;
|
|
46261
46284
|
tag.setAttribute('id', scriptId);
|
|
46262
46285
|
tag.setAttribute('data-version', validVersion);
|
|
46263
46286
|
tag.setAttribute('src', cdnUrl);
|
|
46264
46287
|
document.head.appendChild(tag);
|
|
46265
|
-
|
|
46288
|
+
}
|
|
46289
|
+
// Gets the CDN url for the split checkout widgets bundle
|
|
46290
|
+
function getWidgetsEsmUrl(version) {
|
|
46291
|
+
const validVersion = validateAndBuildVersion(version);
|
|
46292
|
+
let cdnUrl = `https://cdn.jsdelivr.net/npm/@imtbl/sdk@${validVersion}/dist/browser/checkout/widgets-esm.js`;
|
|
46293
|
+
return cdnUrl;
|
|
46266
46294
|
}
|
|
46267
46295
|
|
|
46268
46296
|
const PUBLISHABLE_KEY_PREFIX = 'pk_imapik-';
|
|
@@ -46341,7 +46369,6 @@ const SANDBOX_CONFIGURATION = {
|
|
|
46341
46369
|
},
|
|
46342
46370
|
passport: undefined,
|
|
46343
46371
|
};
|
|
46344
|
-
const WIDGETS_SCRIPT_TIMEOUT = 100;
|
|
46345
46372
|
// Checkout SDK
|
|
46346
46373
|
class Checkout {
|
|
46347
46374
|
readOnlyProviders;
|
|
@@ -46371,26 +46398,44 @@ class Checkout {
|
|
|
46371
46398
|
const checkout = this;
|
|
46372
46399
|
// Preload the configurations
|
|
46373
46400
|
await checkout.config.remote.getConfig();
|
|
46401
|
+
try {
|
|
46402
|
+
const factory = await this.loadEsModules(init.config, init.version);
|
|
46403
|
+
return factory;
|
|
46404
|
+
}
|
|
46405
|
+
catch (err) {
|
|
46406
|
+
throw new CheckoutError('Failed to load widgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR, { error: err });
|
|
46407
|
+
}
|
|
46408
|
+
}
|
|
46409
|
+
async loadUmdBundle(config, version) {
|
|
46410
|
+
const checkout = this;
|
|
46374
46411
|
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
46412
|
try {
|
|
46387
|
-
const
|
|
46388
|
-
|
|
46389
|
-
|
|
46390
|
-
|
|
46391
|
-
|
|
46392
|
-
|
|
46413
|
+
const scriptId = 'immutable-checkout-widgets-bundle';
|
|
46414
|
+
const validVersion = validateAndBuildVersion(version);
|
|
46415
|
+
// Prevent the script to be loaded more than once
|
|
46416
|
+
// by checking the presence of the script and its version.
|
|
46417
|
+
const initScript = document.getElementById(scriptId);
|
|
46418
|
+
if (initScript) {
|
|
46419
|
+
if (typeof ImmutableCheckoutWidgets !== 'undefined') {
|
|
46420
|
+
resolve(new ImmutableCheckoutWidgets.WidgetsFactory(checkout, config));
|
|
46421
|
+
}
|
|
46422
|
+
else {
|
|
46423
|
+
reject(new CheckoutError('Failed to find ImmutableCheckoutWidgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR));
|
|
46424
|
+
}
|
|
46393
46425
|
}
|
|
46426
|
+
const tag = document.createElement('script');
|
|
46427
|
+
tag.addEventListener('load', () => {
|
|
46428
|
+
if (typeof ImmutableCheckoutWidgets !== 'undefined') {
|
|
46429
|
+
resolve(new ImmutableCheckoutWidgets.WidgetsFactory(checkout, config));
|
|
46430
|
+
}
|
|
46431
|
+
else {
|
|
46432
|
+
reject(new CheckoutError('Failed to find ImmutableCheckoutWidgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR));
|
|
46433
|
+
}
|
|
46434
|
+
});
|
|
46435
|
+
tag.addEventListener('error', (err) => {
|
|
46436
|
+
reject(new CheckoutError('Failed to load widgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR, { error: err }));
|
|
46437
|
+
});
|
|
46438
|
+
loadUnresolvedBundle(tag, scriptId, validVersion);
|
|
46394
46439
|
}
|
|
46395
46440
|
catch (err) {
|
|
46396
46441
|
reject(new CheckoutError('Failed to load widgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR, { error: err }));
|
|
@@ -46398,6 +46443,24 @@ class Checkout {
|
|
|
46398
46443
|
});
|
|
46399
46444
|
return factory;
|
|
46400
46445
|
}
|
|
46446
|
+
async loadEsModules(config, version) {
|
|
46447
|
+
const checkout = this;
|
|
46448
|
+
try {
|
|
46449
|
+
const cdnUrl = getWidgetsEsmUrl(version);
|
|
46450
|
+
// WebpackIgnore comment required to prevent webpack modifying the import statement and
|
|
46451
|
+
// breaking the dynamic import in certain applications integrating checkout
|
|
46452
|
+
const checkoutWidgetsModule = await import(/* webpackIgnore: true */ cdnUrl);
|
|
46453
|
+
if (checkoutWidgetsModule && checkoutWidgetsModule.WidgetsFactory) {
|
|
46454
|
+
return new checkoutWidgetsModule.WidgetsFactory(checkout, config);
|
|
46455
|
+
}
|
|
46456
|
+
}
|
|
46457
|
+
catch (err) {
|
|
46458
|
+
// eslint-disable-next-line no-console
|
|
46459
|
+
console.warn(`Failed to resolve checkout widgets module, falling back to UMD bundle. Error: ${err.message}`);
|
|
46460
|
+
}
|
|
46461
|
+
// Fallback to UMD bundle if esm bundle fails to load
|
|
46462
|
+
return await checkout.loadUmdBundle(config, version);
|
|
46463
|
+
}
|
|
46401
46464
|
/**
|
|
46402
46465
|
* Creates a provider using the given parameters.
|
|
46403
46466
|
* @param {CreateProviderParams} params - The parameters for creating the provider.
|
package/dist/index.d.ts
CHANGED
|
@@ -32218,7 +32218,7 @@ type CheckoutWidgetsConfig = {
|
|
|
32218
32218
|
/**
|
|
32219
32219
|
* Represents the configuration options for instantiating the Checkout Widgets factory.
|
|
32220
32220
|
* @property {WidgetConfiguration} config - global configuration options for the widgets.
|
|
32221
|
-
* @property {SemanticVersion | undefined} version - version of the Checkout widgets bundle
|
|
32221
|
+
* @property {SemanticVersion | undefined} version - version of the Checkout widgets bundle(default latest version will be used).
|
|
32222
32222
|
*/
|
|
32223
32223
|
type WidgetsInit = {
|
|
32224
32224
|
config: WidgetConfiguration;
|
|
@@ -32242,6 +32242,8 @@ declare class Checkout {
|
|
|
32242
32242
|
* @param {WidgetsInit} init - The initialisation parameters for loading the widgets bundle and applying configuration
|
|
32243
32243
|
*/
|
|
32244
32244
|
widgets(init: WidgetsInit): Promise<ImmutableCheckoutWidgets.WidgetsFactory>;
|
|
32245
|
+
private loadUmdBundle;
|
|
32246
|
+
private loadEsModules;
|
|
32245
32247
|
/**
|
|
32246
32248
|
* Creates a provider using the given parameters.
|
|
32247
32249
|
* @param {CreateProviderParams} params - The parameters for creating the provider.
|