@imtbl/sdk 0.4.0-alpha.3 → 0.4.1-alpha
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 +1 -1
- package/dist/browser/checkout.js +2 -2
- package/dist/checkout_widgets.js +1 -1
- package/dist/immutablex_client.d.ts +34 -27
- package/dist/immutablex_client.js +1 -1
- package/dist/index.browser.js +16 -16
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +232 -89
- package/dist/index.d.ts +146 -41
- package/dist/index.js +231 -89
- package/dist/orderbook.d.ts +179 -8
- package/dist/passport.d.ts +38 -28
- package/dist/passport.js +229 -87
- package/dist/provider.d.ts +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -4,13 +4,14 @@ var axios$2 = require('axios');
|
|
|
4
4
|
var coreSdk = require('@imtbl/core-sdk');
|
|
5
5
|
var oidcClientTs = require('oidc-client-ts');
|
|
6
6
|
var jwt_decode = require('jwt-decode');
|
|
7
|
+
var crypto = require('crypto');
|
|
7
8
|
var magicSdk = require('magic-sdk');
|
|
8
9
|
var oidc = require('@magic-ext/oidc');
|
|
10
|
+
var ethers = require('ethers');
|
|
9
11
|
var BN$2 = require('bn.js');
|
|
10
12
|
var encUtils = require('enc-utils');
|
|
11
13
|
var providers = require('@ethersproject/providers');
|
|
12
14
|
var events = require('events');
|
|
13
|
-
var ethers = require('ethers');
|
|
14
15
|
var abi = require('@0xsequence/abi');
|
|
15
16
|
var config = require('@0xsequence/config');
|
|
16
17
|
var FormData$2 = require('form-data');
|
|
@@ -44,6 +45,7 @@ function _interopNamespaceDefault(e) {
|
|
|
44
45
|
return Object.freeze(n);
|
|
45
46
|
}
|
|
46
47
|
|
|
48
|
+
var crypto__namespace = /*#__PURE__*/_interopNamespaceDefault(crypto);
|
|
47
49
|
var encUtils__namespace = /*#__PURE__*/_interopNamespaceDefault(encUtils);
|
|
48
50
|
|
|
49
51
|
exports.Environment = void 0;
|
|
@@ -5551,7 +5553,7 @@ class MultiRollupApiClients {
|
|
|
5551
5553
|
}
|
|
5552
5554
|
|
|
5553
5555
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
5554
|
-
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.4.
|
|
5556
|
+
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.4.1-alpha' };
|
|
5555
5557
|
const createConfig = ({ basePath, headers, }) => {
|
|
5556
5558
|
if (!basePath.trim()) {
|
|
5557
5559
|
throw Error('basePath can not be empty');
|
|
@@ -5611,7 +5613,7 @@ class APIError extends Error {
|
|
|
5611
5613
|
|
|
5612
5614
|
/* eslint-disable implicit-arrow-linebreak */
|
|
5613
5615
|
const defaultHeaders = {
|
|
5614
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.4.
|
|
5616
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.4.1-alpha',
|
|
5615
5617
|
};
|
|
5616
5618
|
/**
|
|
5617
5619
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -5877,7 +5879,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
5877
5879
|
chainID,
|
|
5878
5880
|
coreContractAddress,
|
|
5879
5881
|
registrationContractAddress,
|
|
5880
|
-
sdkVersion: 'ts-immutable-sdk-0.4.
|
|
5882
|
+
sdkVersion: 'ts-immutable-sdk-0.4.1-alpha',
|
|
5881
5883
|
});
|
|
5882
5884
|
/**
|
|
5883
5885
|
* Sets `sdkVersion` at the time of build
|
|
@@ -9601,8 +9603,6 @@ var globalAxios = axios;
|
|
|
9601
9603
|
* https://openapi-generator.tech
|
|
9602
9604
|
* Do not edit the class manually.
|
|
9603
9605
|
*/
|
|
9604
|
-
// Some imports not used depending on template conditions
|
|
9605
|
-
// @ts-ignore
|
|
9606
9606
|
const BASE_PATH = "https://guardian.sandbox.imtbl.com".replace(/\/+$/, "");
|
|
9607
9607
|
/**
|
|
9608
9608
|
*
|
|
@@ -9630,10 +9630,10 @@ class BaseAPI {
|
|
|
9630
9630
|
*/
|
|
9631
9631
|
class RequiredError extends Error {
|
|
9632
9632
|
field;
|
|
9633
|
-
name = "RequiredError";
|
|
9634
9633
|
constructor(field, msg) {
|
|
9635
9634
|
super(msg);
|
|
9636
9635
|
this.field = field;
|
|
9636
|
+
this.name = "RequiredError";
|
|
9637
9637
|
}
|
|
9638
9638
|
}
|
|
9639
9639
|
|
|
@@ -9678,6 +9678,8 @@ const setBearerAuthToObject = async function (object, configuration) {
|
|
|
9678
9678
|
}
|
|
9679
9679
|
};
|
|
9680
9680
|
function setFlattenedQueryParams(urlSearchParams, parameter, key = "") {
|
|
9681
|
+
if (parameter == null)
|
|
9682
|
+
return;
|
|
9681
9683
|
if (typeof parameter === "object") {
|
|
9682
9684
|
if (Array.isArray(parameter)) {
|
|
9683
9685
|
parameter.forEach(item => setFlattenedQueryParams(urlSearchParams, item, key));
|
|
@@ -10048,6 +10050,24 @@ class Configuration {
|
|
|
10048
10050
|
}
|
|
10049
10051
|
}
|
|
10050
10052
|
|
|
10053
|
+
/* tslint:disable */
|
|
10054
|
+
/* eslint-disable */
|
|
10055
|
+
/**
|
|
10056
|
+
* Guardian
|
|
10057
|
+
* Guardian API
|
|
10058
|
+
*
|
|
10059
|
+
* The version of the OpenAPI document: 1.0.0
|
|
10060
|
+
* Contact: support@immutable.com
|
|
10061
|
+
*
|
|
10062
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
10063
|
+
* https://openapi-generator.tech
|
|
10064
|
+
* Do not edit the class manually.
|
|
10065
|
+
*/
|
|
10066
|
+
const TransactionApprovalRequestChainTypeEnum = {
|
|
10067
|
+
Starkex: 'starkex',
|
|
10068
|
+
Evm: 'evm'
|
|
10069
|
+
};
|
|
10070
|
+
|
|
10051
10071
|
// used to sign message with L1 keys. Used for registration
|
|
10052
10072
|
function serializeEthSignature(sig) {
|
|
10053
10073
|
// This is because golang appends a recovery param
|
|
@@ -10155,10 +10175,17 @@ const withPassportError = async (fn, customErrorType) => {
|
|
|
10155
10175
|
};
|
|
10156
10176
|
|
|
10157
10177
|
const keyCrendentials = 'passport_credentials';
|
|
10178
|
+
const KEY_PKCE_STATE = 'pkce_state';
|
|
10179
|
+
const KEY_PKCE_VERIFIER = 'pkce_verifier';
|
|
10158
10180
|
const validCredentialsMinTtlSec = 3600; // 1 hour
|
|
10159
10181
|
class DeviceCredentialsManager {
|
|
10160
10182
|
saveCredentials(tokenResponse) {
|
|
10161
|
-
|
|
10183
|
+
if (this.areValid(tokenResponse)) {
|
|
10184
|
+
localStorage.setItem(keyCrendentials, JSON.stringify(tokenResponse));
|
|
10185
|
+
}
|
|
10186
|
+
else {
|
|
10187
|
+
throw Error('Invalid credentials.');
|
|
10188
|
+
}
|
|
10162
10189
|
}
|
|
10163
10190
|
getCredentials() {
|
|
10164
10191
|
const credentialsJson = localStorage.getItem(keyCrendentials);
|
|
@@ -10176,14 +10203,31 @@ class DeviceCredentialsManager {
|
|
|
10176
10203
|
return false;
|
|
10177
10204
|
}
|
|
10178
10205
|
isTokenValid(jwt) {
|
|
10179
|
-
|
|
10180
|
-
|
|
10181
|
-
|
|
10182
|
-
|
|
10206
|
+
try {
|
|
10207
|
+
const tokenPayload = jwt_decode(jwt);
|
|
10208
|
+
const expiresAt = tokenPayload.exp ?? 0;
|
|
10209
|
+
const now = (Date.now() / 1000) + validCredentialsMinTtlSec;
|
|
10210
|
+
return expiresAt > now;
|
|
10211
|
+
}
|
|
10212
|
+
catch (error) {
|
|
10213
|
+
return false;
|
|
10214
|
+
}
|
|
10183
10215
|
}
|
|
10184
10216
|
clearCredentials() {
|
|
10185
10217
|
localStorage.removeItem(keyCrendentials);
|
|
10186
10218
|
}
|
|
10219
|
+
savePKCEData(data) {
|
|
10220
|
+
localStorage.setItem(KEY_PKCE_STATE, data.state);
|
|
10221
|
+
localStorage.setItem(KEY_PKCE_VERIFIER, data.verifier);
|
|
10222
|
+
}
|
|
10223
|
+
getPKCEData() {
|
|
10224
|
+
const state = localStorage.getItem(KEY_PKCE_STATE);
|
|
10225
|
+
const verifier = localStorage.getItem(KEY_PKCE_VERIFIER);
|
|
10226
|
+
if (state && verifier) {
|
|
10227
|
+
return { state, verifier };
|
|
10228
|
+
}
|
|
10229
|
+
return null;
|
|
10230
|
+
}
|
|
10187
10231
|
}
|
|
10188
10232
|
|
|
10189
10233
|
const formUrlEncodedHeader = {
|
|
@@ -10360,6 +10404,59 @@ class AuthManager {
|
|
|
10360
10404
|
}, formUrlEncodedHeader);
|
|
10361
10405
|
return response.data;
|
|
10362
10406
|
}
|
|
10407
|
+
static base64URLEncode(str) {
|
|
10408
|
+
return str.toString('base64')
|
|
10409
|
+
.replace(/\+/g, '-')
|
|
10410
|
+
.replace(/\//g, '_')
|
|
10411
|
+
.replace(/=/g, '');
|
|
10412
|
+
}
|
|
10413
|
+
static sha256(buffer) {
|
|
10414
|
+
return crypto__namespace.createHash('sha256').update(buffer).digest();
|
|
10415
|
+
}
|
|
10416
|
+
getPKCEAuthorizationUrl() {
|
|
10417
|
+
const verifier = AuthManager.base64URLEncode(crypto__namespace.randomBytes(32));
|
|
10418
|
+
const challenge = AuthManager.base64URLEncode(AuthManager.sha256(verifier));
|
|
10419
|
+
// https://auth0.com/docs/secure/attack-protection/state-parameters
|
|
10420
|
+
const state = AuthManager.base64URLEncode(crypto__namespace.randomBytes(32));
|
|
10421
|
+
this.deviceCredentialsManager.savePKCEData({ state, verifier });
|
|
10422
|
+
return `${this.config.authenticationDomain}/authorize?`
|
|
10423
|
+
+ 'response_type=code'
|
|
10424
|
+
+ `&code_challenge=${challenge}`
|
|
10425
|
+
+ '&code_challenge_method=S256'
|
|
10426
|
+
+ `&client_id=${this.config.oidcConfiguration.clientId}`
|
|
10427
|
+
+ `&redirect_uri=${this.config.oidcConfiguration.redirectUri}`
|
|
10428
|
+
+ `&scope=${this.config.oidcConfiguration.scope}`
|
|
10429
|
+
+ `&state=${state}`
|
|
10430
|
+
+ `&audience=${this.config.oidcConfiguration.audience}`;
|
|
10431
|
+
}
|
|
10432
|
+
async connectImxPKCEFlow(authorizationCode, state) {
|
|
10433
|
+
return withPassportError(async () => {
|
|
10434
|
+
const pkceData = this.deviceCredentialsManager.getPKCEData();
|
|
10435
|
+
if (!pkceData) {
|
|
10436
|
+
throw new Error('No code verifier or state for PKCE');
|
|
10437
|
+
}
|
|
10438
|
+
if (state !== pkceData.state) {
|
|
10439
|
+
throw new Error('Provided state does not match stored state');
|
|
10440
|
+
}
|
|
10441
|
+
const tokenResponse = await this.getPKCEToken(authorizationCode, pkceData.verifier);
|
|
10442
|
+
const user = AuthManager.mapDeviceTokenResponseToDomainUserModel(tokenResponse);
|
|
10443
|
+
// Only persist credentials that contain the necessary data
|
|
10444
|
+
if (user.imx?.ethAddress && user.imx?.starkAddress && user.imx?.userAdminAddress) {
|
|
10445
|
+
this.deviceCredentialsManager.saveCredentials(tokenResponse);
|
|
10446
|
+
}
|
|
10447
|
+
return user;
|
|
10448
|
+
}, PassportErrorType.AUTHENTICATION_ERROR);
|
|
10449
|
+
}
|
|
10450
|
+
async getPKCEToken(authorizationCode, codeVerifier) {
|
|
10451
|
+
const response = await axios$2.post(`${this.config.authenticationDomain}/oauth/token`, {
|
|
10452
|
+
client_id: this.config.oidcConfiguration.clientId,
|
|
10453
|
+
grant_type: 'authorization_code',
|
|
10454
|
+
code_verifier: codeVerifier,
|
|
10455
|
+
code: authorizationCode,
|
|
10456
|
+
redirect_uri: this.config.oidcConfiguration.redirectUri,
|
|
10457
|
+
}, formUrlEncodedHeader);
|
|
10458
|
+
return response.data;
|
|
10459
|
+
}
|
|
10363
10460
|
async connectImxWithCredentials(tokenResponse) {
|
|
10364
10461
|
return withPassportError(async () => {
|
|
10365
10462
|
if (this.deviceCredentialsManager.areValid(tokenResponse)) {
|
|
@@ -10488,6 +10585,53 @@ const retryWithDelay = async (fn, options) => {
|
|
|
10488
10585
|
}
|
|
10489
10586
|
};
|
|
10490
10587
|
|
|
10588
|
+
/**
|
|
10589
|
+
* ProviderErrors should take priority over RpcErrorCodes
|
|
10590
|
+
*/
|
|
10591
|
+
exports.ProviderErrorCode = void 0;
|
|
10592
|
+
(function (ProviderErrorCode) {
|
|
10593
|
+
ProviderErrorCode[ProviderErrorCode["USER_REJECTED_REQUEST"] = 4001] = "USER_REJECTED_REQUEST";
|
|
10594
|
+
ProviderErrorCode[ProviderErrorCode["UNAUTHORIZED"] = 4100] = "UNAUTHORIZED";
|
|
10595
|
+
ProviderErrorCode[ProviderErrorCode["UNSUPPORTED_METHOD"] = 4200] = "UNSUPPORTED_METHOD";
|
|
10596
|
+
ProviderErrorCode[ProviderErrorCode["DISCONNECTED"] = 4900] = "DISCONNECTED";
|
|
10597
|
+
})(exports.ProviderErrorCode || (exports.ProviderErrorCode = {}));
|
|
10598
|
+
exports.RpcErrorCode = void 0;
|
|
10599
|
+
(function (RpcErrorCode) {
|
|
10600
|
+
RpcErrorCode[RpcErrorCode["RPC_SERVER_ERROR"] = -32000] = "RPC_SERVER_ERROR";
|
|
10601
|
+
RpcErrorCode[RpcErrorCode["INVALID_REQUEST"] = -32600] = "INVALID_REQUEST";
|
|
10602
|
+
RpcErrorCode[RpcErrorCode["METHOD_NOT_FOUND"] = -32601] = "METHOD_NOT_FOUND";
|
|
10603
|
+
RpcErrorCode[RpcErrorCode["INVALID_PARAMS"] = -32602] = "INVALID_PARAMS";
|
|
10604
|
+
RpcErrorCode[RpcErrorCode["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
|
|
10605
|
+
RpcErrorCode[RpcErrorCode["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
|
|
10606
|
+
RpcErrorCode[RpcErrorCode["USER_REJECTED_REQUEST"] = -32003] = "USER_REJECTED_REQUEST";
|
|
10607
|
+
})(exports.RpcErrorCode || (exports.RpcErrorCode = {}));
|
|
10608
|
+
class JsonRpcError extends Error {
|
|
10609
|
+
message;
|
|
10610
|
+
code;
|
|
10611
|
+
constructor(code, message) {
|
|
10612
|
+
super(message);
|
|
10613
|
+
this.message = message;
|
|
10614
|
+
this.code = code;
|
|
10615
|
+
}
|
|
10616
|
+
}
|
|
10617
|
+
|
|
10618
|
+
const convertBigNumberishToString = (value) => ethers.BigNumber.from(value).toString();
|
|
10619
|
+
const transformGuardianTransactions = (txs) => {
|
|
10620
|
+
try {
|
|
10621
|
+
return txs.map((t) => ({
|
|
10622
|
+
delegateCall: t.delegateCall === true,
|
|
10623
|
+
revertOnError: t.revertOnError === true,
|
|
10624
|
+
gasLimit: t.gasLimit ? convertBigNumberishToString(t.gasLimit) : '0',
|
|
10625
|
+
target: t.to ?? ethers.ethers.constants.AddressZero,
|
|
10626
|
+
value: t.value ? convertBigNumberishToString(t.value) : '0',
|
|
10627
|
+
data: t.data ? t.data.toString() : '0x00',
|
|
10628
|
+
}));
|
|
10629
|
+
}
|
|
10630
|
+
catch (error) {
|
|
10631
|
+
const errorMessage = (error instanceof Error) ? error.message : String(error);
|
|
10632
|
+
throw new JsonRpcError(exports.RpcErrorCode.INVALID_PARAMS, `Transaction failed to parsing: ${errorMessage}`);
|
|
10633
|
+
}
|
|
10634
|
+
};
|
|
10491
10635
|
class GuardianClient {
|
|
10492
10636
|
transactionAPI;
|
|
10493
10637
|
confirmationScreen;
|
|
@@ -10522,7 +10666,7 @@ class GuardianClient {
|
|
|
10522
10666
|
});
|
|
10523
10667
|
const { confirmationRequired } = evaluateStarkexRes.data;
|
|
10524
10668
|
if (confirmationRequired) {
|
|
10525
|
-
const confirmationResult = await this.confirmationScreen.startGuardianTransaction(payloadHash, this.imxEtherAddress);
|
|
10669
|
+
const confirmationResult = await this.confirmationScreen.startGuardianTransaction(payloadHash, this.imxEtherAddress, TransactionApprovalRequestChainTypeEnum.Starkex);
|
|
10526
10670
|
if (!confirmationResult.confirmed) {
|
|
10527
10671
|
throw new Error('Transaction rejected by user');
|
|
10528
10672
|
}
|
|
@@ -10531,6 +10675,47 @@ class GuardianClient {
|
|
|
10531
10675
|
this.confirmationScreen.closeWindow();
|
|
10532
10676
|
}
|
|
10533
10677
|
}
|
|
10678
|
+
async evaluateEVMTransaction({ chainId, nonce, user, metaTransactions, }) {
|
|
10679
|
+
const headers = { Authorization: `Bearer ${user.accessToken}` };
|
|
10680
|
+
const guardianTransactions = transformGuardianTransactions(metaTransactions);
|
|
10681
|
+
try {
|
|
10682
|
+
const transactionEvaluationResponseAxiosResponse = await this.transactionAPI.evaluateTransaction({
|
|
10683
|
+
id: 'evm',
|
|
10684
|
+
transactionEvaluationRequest: {
|
|
10685
|
+
chainType: 'evm',
|
|
10686
|
+
chainId,
|
|
10687
|
+
transactionData: {
|
|
10688
|
+
nonce,
|
|
10689
|
+
userAddress: user.zkEvm.ethAddress,
|
|
10690
|
+
metaTransactions: guardianTransactions,
|
|
10691
|
+
},
|
|
10692
|
+
},
|
|
10693
|
+
}, { headers });
|
|
10694
|
+
return transactionEvaluationResponseAxiosResponse.data;
|
|
10695
|
+
}
|
|
10696
|
+
catch (error) {
|
|
10697
|
+
const errorMessage = (error instanceof Error) ? error.message : String(error);
|
|
10698
|
+
throw new JsonRpcError(exports.RpcErrorCode.INTERNAL_ERROR, `Transaction failed to validate with error: ${errorMessage}`);
|
|
10699
|
+
}
|
|
10700
|
+
}
|
|
10701
|
+
async validateEVMTransaction({ chainId, nonce, user, metaTransactions, }) {
|
|
10702
|
+
const transactionEvaluationResponse = await this.evaluateEVMTransaction({
|
|
10703
|
+
chainId,
|
|
10704
|
+
nonce,
|
|
10705
|
+
user,
|
|
10706
|
+
metaTransactions,
|
|
10707
|
+
});
|
|
10708
|
+
const { confirmationRequired, transactionId } = transactionEvaluationResponse;
|
|
10709
|
+
if (confirmationRequired && !!transactionId) {
|
|
10710
|
+
const confirmationResult = await this.confirmationScreen.startGuardianTransaction(transactionId, this.imxEtherAddress, TransactionApprovalRequestChainTypeEnum.Evm, chainId);
|
|
10711
|
+
if (!confirmationResult.confirmed) {
|
|
10712
|
+
throw new JsonRpcError(exports.RpcErrorCode.USER_REJECTED_REQUEST, 'Transaction rejected by user ');
|
|
10713
|
+
}
|
|
10714
|
+
}
|
|
10715
|
+
else {
|
|
10716
|
+
this.confirmationScreen.closeWindow();
|
|
10717
|
+
}
|
|
10718
|
+
}
|
|
10534
10719
|
}
|
|
10535
10720
|
|
|
10536
10721
|
async function exchangeTransfer$1({ user, starkSigner, request, exchangesApi, }) {
|
|
@@ -10969,6 +11154,10 @@ class PassportImxProviderFactory {
|
|
|
10969
11154
|
const user = await this.authManager.connectImxDeviceFlow(deviceCode, interval, timeoutMs);
|
|
10970
11155
|
return this.createProviderInstance(user);
|
|
10971
11156
|
}
|
|
11157
|
+
async getProviderWithPKCEFlow(authorizationCode, state) {
|
|
11158
|
+
const user = await this.authManager.connectImxPKCEFlow(authorizationCode, state);
|
|
11159
|
+
return this.createProviderInstance(user);
|
|
11160
|
+
}
|
|
10972
11161
|
async getProviderWithCredentials(tokenResponse) {
|
|
10973
11162
|
const user = await this.authManager.connectImxWithCredentials(tokenResponse);
|
|
10974
11163
|
if (!user) {
|
|
@@ -11232,7 +11421,7 @@ class ConfirmationScreen {
|
|
|
11232
11421
|
}, CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION);
|
|
11233
11422
|
});
|
|
11234
11423
|
}
|
|
11235
|
-
startGuardianTransaction(transactionId, imxEtherAddress) {
|
|
11424
|
+
startGuardianTransaction(transactionId, imxEtherAddress, chainType, chainId) {
|
|
11236
11425
|
return new Promise((resolve, reject) => {
|
|
11237
11426
|
const messageHandler = ({ data, origin }) => {
|
|
11238
11427
|
if (origin !== this.config.passportDomain
|
|
@@ -11261,7 +11450,16 @@ class ConfirmationScreen {
|
|
|
11261
11450
|
return;
|
|
11262
11451
|
}
|
|
11263
11452
|
// eslint-disable-next-line max-len
|
|
11264
|
-
|
|
11453
|
+
let href = '';
|
|
11454
|
+
if (chainType === TransactionApprovalRequestChainTypeEnum.Starkex) {
|
|
11455
|
+
// eslint-disable-next-line max-len
|
|
11456
|
+
href = `${this.config.passportDomain}/transaction-confirmation/transaction.html?transactionId=${transactionId}&imxEtherAddress=${imxEtherAddress}&chainType=starkex`;
|
|
11457
|
+
}
|
|
11458
|
+
else {
|
|
11459
|
+
// eslint-disable-next-line max-len
|
|
11460
|
+
href = `${this.config.passportDomain}/transaction-confirmation/zkevm?transactionId=${transactionId}&imxEtherAddress=${imxEtherAddress}&chainType=evm&chainId=${chainId}`;
|
|
11461
|
+
}
|
|
11462
|
+
this.confirmationWindow.location.href = href;
|
|
11265
11463
|
// https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128
|
|
11266
11464
|
const timer = setInterval(() => {
|
|
11267
11465
|
if (this.confirmationWindow?.closed) {
|
|
@@ -11369,35 +11567,6 @@ class RelayerClient {
|
|
|
11369
11567
|
}
|
|
11370
11568
|
}
|
|
11371
11569
|
|
|
11372
|
-
/**
|
|
11373
|
-
* ProviderErrors should take priority over RpcErrorCodes
|
|
11374
|
-
*/
|
|
11375
|
-
exports.ProviderErrorCode = void 0;
|
|
11376
|
-
(function (ProviderErrorCode) {
|
|
11377
|
-
ProviderErrorCode[ProviderErrorCode["USER_REJECTED_REQUEST"] = 4001] = "USER_REJECTED_REQUEST";
|
|
11378
|
-
ProviderErrorCode[ProviderErrorCode["UNAUTHORIZED"] = 4100] = "UNAUTHORIZED";
|
|
11379
|
-
ProviderErrorCode[ProviderErrorCode["UNSUPPORTED_METHOD"] = 4200] = "UNSUPPORTED_METHOD";
|
|
11380
|
-
ProviderErrorCode[ProviderErrorCode["DISCONNECTED"] = 4900] = "DISCONNECTED";
|
|
11381
|
-
})(exports.ProviderErrorCode || (exports.ProviderErrorCode = {}));
|
|
11382
|
-
exports.RpcErrorCode = void 0;
|
|
11383
|
-
(function (RpcErrorCode) {
|
|
11384
|
-
RpcErrorCode[RpcErrorCode["RPC_SERVER_ERROR"] = -32000] = "RPC_SERVER_ERROR";
|
|
11385
|
-
RpcErrorCode[RpcErrorCode["INVALID_REQUEST"] = -32600] = "INVALID_REQUEST";
|
|
11386
|
-
RpcErrorCode[RpcErrorCode["METHOD_NOT_FOUND"] = -32601] = "METHOD_NOT_FOUND";
|
|
11387
|
-
RpcErrorCode[RpcErrorCode["INVALID_PARAMS"] = -32602] = "INVALID_PARAMS";
|
|
11388
|
-
RpcErrorCode[RpcErrorCode["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
|
|
11389
|
-
RpcErrorCode[RpcErrorCode["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
|
|
11390
|
-
})(exports.RpcErrorCode || (exports.RpcErrorCode = {}));
|
|
11391
|
-
class JsonRpcError extends Error {
|
|
11392
|
-
message;
|
|
11393
|
-
code;
|
|
11394
|
-
constructor(code, message) {
|
|
11395
|
-
super(message);
|
|
11396
|
-
this.message = message;
|
|
11397
|
-
this.code = code;
|
|
11398
|
-
}
|
|
11399
|
-
}
|
|
11400
|
-
|
|
11401
11570
|
const MESSAGE_TO_SIGN = 'Only sign this message from Immutable Passport';
|
|
11402
11571
|
async function registerZkEvmUser({ authManager, magicProvider, multiRollupApiClients, accessToken, }) {
|
|
11403
11572
|
const web3Provider = new providers.Web3Provider(magicProvider);
|
|
@@ -11525,46 +11694,9 @@ const chainIdNumber = (chainId) => {
|
|
|
11525
11694
|
|
|
11526
11695
|
const MAX_TRANSACTION_HASH_RETRIEVAL_RETRIES = 30;
|
|
11527
11696
|
const TRANSACTION_HASH_RETRIEVAL_WAIT = 1000;
|
|
11528
|
-
const
|
|
11529
|
-
const
|
|
11530
|
-
|
|
11531
|
-
return txs.map((t) => ({
|
|
11532
|
-
delegateCall: t.delegateCall === true,
|
|
11533
|
-
revertOnError: t.revertOnError === true,
|
|
11534
|
-
gasLimit: t.gasLimit ? converBigNumberishToNumber(t.gasLimit).toString() : '0',
|
|
11535
|
-
target: t.to ?? ethers.ethers.constants.AddressZero,
|
|
11536
|
-
value: t.value ? converBigNumberishToNumber(t.value).toString() : '0',
|
|
11537
|
-
data: t.data ? t.data.toString() : '0x00',
|
|
11538
|
-
}));
|
|
11539
|
-
}
|
|
11540
|
-
catch (error) {
|
|
11541
|
-
const errorMessage = (error instanceof Error) ? error.message : String(error);
|
|
11542
|
-
throw new JsonRpcError(exports.RpcErrorCode.INVALID_PARAMS, `Transaction failed to parsing: ${errorMessage}`);
|
|
11543
|
-
}
|
|
11544
|
-
};
|
|
11545
|
-
const guardianValidation = async ({ transactionAPI, chainId, nonce, user, metaTransactions, }) => {
|
|
11546
|
-
const headers = { Authorization: `Bearer ${user.accessToken}` };
|
|
11547
|
-
const guardianTransactions = transformGardianTransactions(metaTransactions);
|
|
11548
|
-
try {
|
|
11549
|
-
await transactionAPI.evaluateTransaction({
|
|
11550
|
-
id: 'evm',
|
|
11551
|
-
transactionEvaluationRequest: {
|
|
11552
|
-
chainType: 'evm',
|
|
11553
|
-
chainId,
|
|
11554
|
-
transactionData: {
|
|
11555
|
-
nonce,
|
|
11556
|
-
userAddress: user.zkEvm.ethAddress,
|
|
11557
|
-
metaTransactions: guardianTransactions,
|
|
11558
|
-
},
|
|
11559
|
-
},
|
|
11560
|
-
}, { headers });
|
|
11561
|
-
}
|
|
11562
|
-
catch (error) {
|
|
11563
|
-
const errorMessage = (error instanceof Error) ? error.message : String(error);
|
|
11564
|
-
throw new JsonRpcError(exports.RpcErrorCode.INTERNAL_ERROR, `Transaction failed to validate with error: ${errorMessage}`);
|
|
11565
|
-
}
|
|
11566
|
-
};
|
|
11567
|
-
const sendTransaction = async ({ params, magicProvider, jsonRpcProvider, relayerClient, transactionAPI, config, user, }) => {
|
|
11697
|
+
const sendTransaction = async ({ params, magicProvider, jsonRpcProvider, relayerClient, guardianClient, config, user, }) => {
|
|
11698
|
+
const popupWindowSize = { width: 480, height: 580 };
|
|
11699
|
+
guardianClient.loading(popupWindowSize);
|
|
11568
11700
|
const transactionRequest = params[0];
|
|
11569
11701
|
if (!transactionRequest.to) {
|
|
11570
11702
|
throw new JsonRpcError(exports.RpcErrorCode.INVALID_PARAMS, 'eth_sendTransaction requires a "to" field');
|
|
@@ -11602,10 +11734,9 @@ const sendTransaction = async ({ params, magicProvider, jsonRpcProvider, relayer
|
|
|
11602
11734
|
value: imxFeeOption.tokenPrice,
|
|
11603
11735
|
revertOnError: true,
|
|
11604
11736
|
};
|
|
11605
|
-
await
|
|
11606
|
-
transactionAPI,
|
|
11737
|
+
await guardianClient.validateEVMTransaction({
|
|
11607
11738
|
chainId: config.zkEvmChainId,
|
|
11608
|
-
nonce:
|
|
11739
|
+
nonce: convertBigNumberishToString(nonce),
|
|
11609
11740
|
user,
|
|
11610
11741
|
metaTransactions: [metaTransaction, feeMetaTransaction],
|
|
11611
11742
|
});
|
|
@@ -11685,10 +11816,16 @@ class ZkEvmProvider {
|
|
|
11685
11816
|
if (!this.isLoggedIn()) {
|
|
11686
11817
|
throw new JsonRpcError(exports.ProviderErrorCode.UNAUTHORIZED, 'Unauthorised - call eth_requestAccounts first');
|
|
11687
11818
|
}
|
|
11819
|
+
const guardianClient = new GuardianClient({
|
|
11820
|
+
imxPublicApiDomain: this.config.imxPublicApiDomain,
|
|
11821
|
+
accessToken: this.user.accessToken,
|
|
11822
|
+
confirmationScreen: this.confirmationScreen,
|
|
11823
|
+
imxEtherAddress: this.user?.imx?.ethAddress || '',
|
|
11824
|
+
});
|
|
11688
11825
|
return sendTransaction({
|
|
11689
11826
|
params: request.params || [],
|
|
11690
11827
|
magicProvider: this.magicProvider,
|
|
11691
|
-
|
|
11828
|
+
guardianClient,
|
|
11692
11829
|
jsonRpcProvider: this.jsonRpcProvider,
|
|
11693
11830
|
config: this.config,
|
|
11694
11831
|
relayerClient: this.relayerClient,
|
|
@@ -11854,6 +11991,12 @@ class Passport {
|
|
|
11854
11991
|
async connectImxDeviceFlow(deviceCode, interval, timeoutMs) {
|
|
11855
11992
|
return this.passportImxProviderFactory.getProviderWithDeviceFlow(deviceCode, interval, timeoutMs);
|
|
11856
11993
|
}
|
|
11994
|
+
getPKCEAuthorizationUrl() {
|
|
11995
|
+
return this.authManager.getPKCEAuthorizationUrl();
|
|
11996
|
+
}
|
|
11997
|
+
async connectImxPKCEFlow(authorizationCode, state) {
|
|
11998
|
+
return this.passportImxProviderFactory.getProviderWithPKCEFlow(authorizationCode, state);
|
|
11999
|
+
}
|
|
11857
12000
|
/**
|
|
11858
12001
|
* @returns {boolean} the stored device flow credentials if they exist
|
|
11859
12002
|
*/
|
|
@@ -28719,7 +28862,7 @@ class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
|
|
|
28719
28862
|
function $parcel$export(e, n, v, s) {
|
|
28720
28863
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
28721
28864
|
}
|
|
28722
|
-
const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.4.
|
|
28865
|
+
const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.4.1-alpha";
|
|
28723
28866
|
const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
|
|
28724
28867
|
const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
|
|
28725
28868
|
|