@imtbl/wallet 2.12.7-alpha.1 → 2.12.7-alpha.10
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/README.md +1 -31
- package/dist/browser/index.js +30 -204
- package/dist/node/index.cjs +55 -244
- package/dist/node/index.js +29 -203
- package/dist/types/confirmation/confirmation.d.ts +1 -1
- package/dist/types/connectWallet.d.ts +3 -2
- package/dist/types/constants.d.ts +0 -9
- package/dist/types/index.d.ts +2 -4
- package/dist/types/{network/presets.d.ts → presets.d.ts} +1 -55
- package/dist/types/types.d.ts +0 -12
- package/dist/types/zkEvm/types.d.ts +10 -3
- package/package.json +4 -9
- package/src/confirmation/confirmation.ts +4 -14
- package/src/connectWallet.test.ts +1 -34
- package/src/connectWallet.ts +40 -81
- package/src/constants.ts +0 -13
- package/src/guardian/index.ts +0 -2
- package/src/index.ts +2 -18
- package/src/presets.ts +92 -0
- package/src/types.ts +0 -16
- package/src/zkEvm/types.ts +10 -4
- package/dist/types/network/chainRegistry.d.ts +0 -13
- package/dist/types/sequence/sequenceProvider.d.ts +0 -21
- package/dist/types/sequence/signer/identityInstrumentSigner.d.ts +0 -15
- package/dist/types/sequence/signer/index.d.ts +0 -21
- package/dist/types/sequence/signer/privateKeySigner.d.ts +0 -15
- package/dist/types/sequence/signer/types.d.ts +0 -14
- package/dist/types/sequence/user/index.d.ts +0 -2
- package/dist/types/sequence/user/registerUser.d.ts +0 -18
- package/src/network/chainRegistry.test.ts +0 -64
- package/src/network/chainRegistry.ts +0 -74
- package/src/network/presets.ts +0 -185
- package/src/sequence/sequenceProvider.ts +0 -284
- package/src/sequence/signer/identityInstrumentSigner.ts +0 -195
- package/src/sequence/signer/index.ts +0 -41
- package/src/sequence/signer/privateKeySigner.ts +0 -112
- package/src/sequence/signer/types.ts +0 -24
- package/src/sequence/user/index.ts +0 -2
- package/src/sequence/user/registerUser.ts +0 -101
|
@@ -15,7 +15,7 @@ export default class ConfirmationScreen {
|
|
|
15
15
|
constructor(config: IAuthConfiguration);
|
|
16
16
|
private getHref;
|
|
17
17
|
requestConfirmation(transactionId: string, etherAddress: string, chainType: GeneratedClients.mr.TransactionApprovalRequestChainTypeEnum, chainId?: string): Promise<ConfirmationResult>;
|
|
18
|
-
requestMessageConfirmation(messageID: string, etherAddress: string, messageType
|
|
18
|
+
requestMessageConfirmation(messageID: string, etherAddress: string, messageType?: MessageType): Promise<ConfirmationResult>;
|
|
19
19
|
showServiceUnavailable(): Promise<void>;
|
|
20
20
|
loading(popupOptions?: {
|
|
21
21
|
width: number;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ZkEvmProvider } from './zkEvm/zkEvmProvider';
|
|
2
|
+
import { ConnectWalletOptions } from './types';
|
|
2
3
|
/**
|
|
3
4
|
* Connect wallet with the provided configuration
|
|
4
5
|
*
|
|
@@ -25,4 +26,4 @@ import { ConnectWalletOptions, Provider } from './types';
|
|
|
25
26
|
* const accounts = await provider.request({ method: 'eth_requestAccounts' });
|
|
26
27
|
* ```
|
|
27
28
|
*/
|
|
28
|
-
export declare function connectWallet(config?: ConnectWalletOptions): Promise<
|
|
29
|
+
export declare function connectWallet(config?: ConnectWalletOptions): Promise<ZkEvmProvider>;
|
|
@@ -5,15 +5,6 @@
|
|
|
5
5
|
export declare const IMMUTABLE_ZKEVM_MAINNET_CHAIN_ID = 13371;
|
|
6
6
|
/** Immutable zkEVM Testnet chain ID */
|
|
7
7
|
export declare const IMMUTABLE_ZKEVM_TESTNET_CHAIN_ID = 13473;
|
|
8
|
-
/**
|
|
9
|
-
* Chain ID constants for Arbitrum networks
|
|
10
|
-
*/
|
|
11
|
-
/** Arbitrum One Mainnet chain ID */
|
|
12
|
-
export declare const ARBITRUM_ONE_CHAIN_ID = 42161;
|
|
13
|
-
/** Arbitrum Sepolia Testnet chain ID */
|
|
14
|
-
export declare const ARBITRUM_SEPOLIA_CHAIN_ID = 421614;
|
|
15
|
-
/** Ethereum Sepolia Testnet chain ID */
|
|
16
|
-
export declare const ETHEREUM_SEPOLIA_CHAIN_ID = 11155111;
|
|
17
8
|
/**
|
|
18
9
|
* Magic configuration for Immutable networks
|
|
19
10
|
* @internal
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
export { connectWallet } from './connectWallet';
|
|
2
|
-
export { IMMUTABLE_ZKEVM_MAINNET_CHAIN_ID, IMMUTABLE_ZKEVM_TESTNET_CHAIN_ID,
|
|
3
|
-
export { IMMUTABLE_ZKEVM_MAINNET, IMMUTABLE_ZKEVM_TESTNET, IMMUTABLE_ZKEVM_MULTICHAIN, IMMUTABLE_ZKEVM_MAINNET_CHAIN, IMMUTABLE_ZKEVM_TESTNET_CHAIN, DEFAULT_CHAINS,
|
|
4
|
-
export { getChainConfig, getEvmChainFromChainId } from './network/chainRegistry';
|
|
2
|
+
export { IMMUTABLE_ZKEVM_MAINNET_CHAIN_ID, IMMUTABLE_ZKEVM_TESTNET_CHAIN_ID, } from './constants';
|
|
3
|
+
export { IMMUTABLE_ZKEVM_MAINNET, IMMUTABLE_ZKEVM_TESTNET, IMMUTABLE_ZKEVM_MULTICHAIN, IMMUTABLE_ZKEVM_MAINNET_CHAIN, IMMUTABLE_ZKEVM_TESTNET_CHAIN, DEFAULT_CHAINS, } from './presets';
|
|
5
4
|
export { ZkEvmProvider } from './zkEvm/zkEvmProvider';
|
|
6
|
-
export { SequenceProvider } from './sequence/sequenceProvider';
|
|
7
5
|
export { WalletConfiguration } from './config';
|
|
8
6
|
export * from './types';
|
|
9
7
|
export { WalletError, WalletErrorType } from './errors';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChainConfig } from '
|
|
1
|
+
import { ChainConfig } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Immutable zkEVM Mainnet chain configuration
|
|
4
4
|
*/
|
|
@@ -7,18 +7,6 @@ export declare const IMMUTABLE_ZKEVM_MAINNET_CHAIN: ChainConfig;
|
|
|
7
7
|
* Immutable zkEVM Testnet chain configuration
|
|
8
8
|
*/
|
|
9
9
|
export declare const IMMUTABLE_ZKEVM_TESTNET_CHAIN: ChainConfig;
|
|
10
|
-
/**
|
|
11
|
-
* Arbitrum One Mainnet chain configuration
|
|
12
|
-
*/
|
|
13
|
-
export declare const ARBITRUM_ONE_CHAIN: ChainConfig;
|
|
14
|
-
/**
|
|
15
|
-
* Arbitrum Sepolia Testnet chain configuration
|
|
16
|
-
*/
|
|
17
|
-
export declare const ARBITRUM_SEPOLIA_CHAIN: ChainConfig;
|
|
18
|
-
/**
|
|
19
|
-
* Ethereum Sepolia Testnet chain configuration
|
|
20
|
-
*/
|
|
21
|
-
export declare const ETHEREUM_SEPOLIA_CHAIN: ChainConfig;
|
|
22
10
|
/**
|
|
23
11
|
* Default chains (testnet + mainnet)
|
|
24
12
|
* Testnet is first (default initial chain)
|
|
@@ -68,45 +56,3 @@ export declare const IMMUTABLE_ZKEVM_TESTNET: {
|
|
|
68
56
|
export declare const IMMUTABLE_ZKEVM_MULTICHAIN: {
|
|
69
57
|
chains: ChainConfig[];
|
|
70
58
|
};
|
|
71
|
-
/**
|
|
72
|
-
* Arbitrum mainnet only preset
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* ```typescript
|
|
76
|
-
* const provider = await connectWallet({
|
|
77
|
-
* ...ARBITRUM_ONE_MAINNET,
|
|
78
|
-
* auth,
|
|
79
|
-
* });
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
82
|
-
export declare const ARBITRUM_ONE: {
|
|
83
|
-
chains: ChainConfig[];
|
|
84
|
-
};
|
|
85
|
-
/**
|
|
86
|
-
* Arbitrum testnet only preset
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* ```typescript
|
|
90
|
-
* const provider = await connectWallet({
|
|
91
|
-
* ...ARBITRUM_SEPOLIA,
|
|
92
|
-
* auth,
|
|
93
|
-
* });
|
|
94
|
-
* ```
|
|
95
|
-
*/
|
|
96
|
-
export declare const ARBITRUM_SEPOLIA: {
|
|
97
|
-
chains: ChainConfig[];
|
|
98
|
-
};
|
|
99
|
-
/**
|
|
100
|
-
* Ethereum Sepolia testnet only preset
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
* ```typescript
|
|
104
|
-
* const provider = await connectWallet({
|
|
105
|
-
* ...ETHEREUM_SEPOLIA,
|
|
106
|
-
* auth,
|
|
107
|
-
* });
|
|
108
|
-
* ```
|
|
109
|
-
*/
|
|
110
|
-
export declare const ETHEREUM_SEPOLIA: {
|
|
111
|
-
chains: ChainConfig[];
|
|
112
|
-
};
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { Flow } from '@imtbl/metrics';
|
|
2
2
|
import { TypedEventEmitter, User } from '@imtbl/auth';
|
|
3
3
|
import { JsonRpcError } from './zkEvm/JsonRpcError';
|
|
4
|
-
export declare enum EvmChain {
|
|
5
|
-
ZKEVM = "zkevm",
|
|
6
|
-
ARBITRUM_ONE = "arbitrum_one"
|
|
7
|
-
}
|
|
8
4
|
/**
|
|
9
5
|
* A viem-compatible signer interface for wallet operations.
|
|
10
6
|
* This replaces ethers' AbstractSigner/Signer.
|
|
@@ -166,14 +162,6 @@ export interface ChainConfig {
|
|
|
166
162
|
* Defaults to 'https://tee.express.magiclabs.com'
|
|
167
163
|
*/
|
|
168
164
|
magicTeeBasePath?: string;
|
|
169
|
-
/** Preferred token symbol for relayer fees (default: 'IMX') */
|
|
170
|
-
feeTokenSymbol?: string;
|
|
171
|
-
/** Sequence RPC node URL TODO: check if this can be removed and only use rpcUrl */
|
|
172
|
-
nodeUrl?: string;
|
|
173
|
-
/**
|
|
174
|
-
* Sequence Identity Instrument endpoint (for non-zkEVM chains in prod/sandbox)
|
|
175
|
-
*/
|
|
176
|
-
sequenceIdentityInstrumentEndpoint?: string;
|
|
177
165
|
}
|
|
178
166
|
/**
|
|
179
167
|
* Popup overlay options for wallet UI
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { JsonRpcError } from './JsonRpcError';
|
|
2
|
-
import type { Provider as ProviderType } from '../types';
|
|
3
2
|
export declare enum RelayerTransactionStatus {
|
|
4
3
|
PENDING = "PENDING",
|
|
5
4
|
SUBMITTED = "SUBMITTED",
|
|
@@ -83,8 +82,16 @@ export interface JsonRpcResponsePayload {
|
|
|
83
82
|
jsonrpc?: string;
|
|
84
83
|
id?: string | number;
|
|
85
84
|
}
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
/**
|
|
86
|
+
* EIP-1193 Provider Interface
|
|
87
|
+
* Standard Ethereum provider interface
|
|
88
|
+
*/
|
|
89
|
+
export type Provider = {
|
|
90
|
+
request: (request: RequestArguments) => Promise<any>;
|
|
91
|
+
on: (event: string, listener: (...args: any[]) => void) => void;
|
|
92
|
+
removeListener: (event: string, listener: (...args: any[]) => void) => void;
|
|
93
|
+
isPassport: boolean;
|
|
94
|
+
};
|
|
88
95
|
export declare enum ProviderEvent {
|
|
89
96
|
ACCOUNTS_CHANGED = "accountsChanged"
|
|
90
97
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imtbl/wallet",
|
|
3
|
-
"version": "2.12.7-alpha.
|
|
3
|
+
"version": "2.12.7-alpha.10",
|
|
4
4
|
"description": "Wallet SDK for Immutable",
|
|
5
5
|
"author": "Immutable",
|
|
6
6
|
"bugs": "https://github.com/immutable/ts-immutable-sdk/issues",
|
|
@@ -25,16 +25,12 @@
|
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@imtbl/auth": "2.12.7-alpha.
|
|
29
|
-
"@imtbl/generated-clients": "2.12.7-alpha.
|
|
30
|
-
"@imtbl/metrics": "2.12.7-alpha.
|
|
28
|
+
"@imtbl/auth": "2.12.7-alpha.10",
|
|
29
|
+
"@imtbl/generated-clients": "2.12.7-alpha.10",
|
|
30
|
+
"@imtbl/metrics": "2.12.7-alpha.10",
|
|
31
31
|
"viem": "~2.18.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@0xsequence/identity-instrument": "3.0.0-beta.10",
|
|
35
|
-
"@0xsequence/wallet-wdk": "3.0.0-beta.10",
|
|
36
|
-
"@0xsequence/wallet-core": "3.0.0-beta.10",
|
|
37
|
-
"@0xsequence/wallet-primitives": "3.0.0-beta.10",
|
|
38
34
|
"@swc/core": "^1.4.2",
|
|
39
35
|
"@swc/jest": "^0.2.37",
|
|
40
36
|
"@types/jest": "^29.5.12",
|
|
@@ -42,7 +38,6 @@
|
|
|
42
38
|
"@jest/test-sequencer": "^29.7.0",
|
|
43
39
|
"jest": "^29.7.0",
|
|
44
40
|
"jest-environment-jsdom": "^29.4.3",
|
|
45
|
-
"ox": "^0.9.17",
|
|
46
41
|
"ts-node": "^10.9.1",
|
|
47
42
|
"tsup": "^8.3.0",
|
|
48
43
|
"typescript": "^5.6.2"
|
|
@@ -10,8 +10,6 @@ import {
|
|
|
10
10
|
import { openPopupCenter } from './popup';
|
|
11
11
|
import { IAuthConfiguration } from '@imtbl/auth';
|
|
12
12
|
import ConfirmationOverlay from '../overlay/confirmationOverlay';
|
|
13
|
-
import { getEvmChainFromChainId } from '../network/chainRegistry';
|
|
14
|
-
import { EvmChain } from '../types';
|
|
15
13
|
|
|
16
14
|
const CONFIRMATION_WINDOW_TITLE = 'Confirm this transaction';
|
|
17
15
|
const CONFIRMATION_WINDOW_HEIGHT = 720;
|
|
@@ -107,10 +105,7 @@ export default class ConfirmationScreen {
|
|
|
107
105
|
if (chainType === GeneratedClients.mr.TransactionApprovalRequestChainTypeEnum.Starkex) {
|
|
108
106
|
href = this.getHref('transaction', { transactionId, etherAddress, chainType });
|
|
109
107
|
} else {
|
|
110
|
-
|
|
111
|
-
const chain = chainId ? getEvmChainFromChainId(chainId) : EvmChain.ZKEVM;
|
|
112
|
-
const chainPath = chain.replace('_', '-');
|
|
113
|
-
href = this.getHref(`${chainPath}/transaction`, {
|
|
108
|
+
href = this.getHref('zkevm/transaction', {
|
|
114
109
|
transactionID: transactionId, etherAddress, chainType, chainID: chainId,
|
|
115
110
|
});
|
|
116
111
|
}
|
|
@@ -122,8 +117,7 @@ export default class ConfirmationScreen {
|
|
|
122
117
|
requestMessageConfirmation(
|
|
123
118
|
messageID: string,
|
|
124
119
|
etherAddress: string,
|
|
125
|
-
messageType
|
|
126
|
-
chainId: string,
|
|
120
|
+
messageType?: MessageType,
|
|
127
121
|
): Promise<ConfirmationResult> {
|
|
128
122
|
return new Promise((resolve, reject) => {
|
|
129
123
|
const messageHandler = ({ data, origin }: MessageEvent) => {
|
|
@@ -163,14 +157,10 @@ export default class ConfirmationScreen {
|
|
|
163
157
|
};
|
|
164
158
|
|
|
165
159
|
window.addEventListener('message', messageHandler);
|
|
166
|
-
|
|
167
|
-
const chain = getEvmChainFromChainId(chainId);
|
|
168
|
-
const chainPath = chain.replace('_', '-');
|
|
169
|
-
const href = this.getHref(`${chainPath}/message`, {
|
|
160
|
+
const href = this.getHref('zkevm/message', {
|
|
170
161
|
messageID,
|
|
171
162
|
etherAddress,
|
|
172
|
-
|
|
173
|
-
messageType,
|
|
163
|
+
...(messageType ? { messageType } : {}),
|
|
174
164
|
});
|
|
175
165
|
this.showConfirmationScreen(href, messageHandler, resolve);
|
|
176
166
|
});
|
|
@@ -43,18 +43,6 @@ jest.mock('./zkEvm/zkEvmProvider', () => ({
|
|
|
43
43
|
ZkEvmProvider: jest.fn(),
|
|
44
44
|
}));
|
|
45
45
|
|
|
46
|
-
jest.mock('./sequence/sequenceProvider', () => ({
|
|
47
|
-
SequenceProvider: jest.fn(),
|
|
48
|
-
}));
|
|
49
|
-
|
|
50
|
-
jest.mock('./sequence/signer', () => ({
|
|
51
|
-
createSequenceSigner: jest.fn().mockReturnValue({
|
|
52
|
-
getAddress: jest.fn().mockResolvedValue('0x1234'),
|
|
53
|
-
signPayload: jest.fn(),
|
|
54
|
-
signMessage: jest.fn(),
|
|
55
|
-
}),
|
|
56
|
-
}));
|
|
57
|
-
|
|
58
46
|
jest.mock('./provider/eip6963', () => ({
|
|
59
47
|
announceProvider: jest.fn(),
|
|
60
48
|
passportProviderInfo: { name: 'passport', rdns: 'com.immutable.passport', icon: '' },
|
|
@@ -64,7 +52,6 @@ const { connectWallet } = require('./connectWallet');
|
|
|
64
52
|
|
|
65
53
|
const { announceProvider } = jest.requireMock('./provider/eip6963');
|
|
66
54
|
const { ZkEvmProvider } = jest.requireMock('./zkEvm/zkEvmProvider');
|
|
67
|
-
const { SequenceProvider } = jest.requireMock('./sequence/sequenceProvider');
|
|
68
55
|
|
|
69
56
|
const zkEvmChain = {
|
|
70
57
|
chainId: 13473,
|
|
@@ -74,15 +61,6 @@ const zkEvmChain = {
|
|
|
74
61
|
name: 'Immutable zkEVM Testnet',
|
|
75
62
|
};
|
|
76
63
|
|
|
77
|
-
const arbitrumChain = {
|
|
78
|
-
chainId: 42161,
|
|
79
|
-
rpcUrl: 'https://arb1.arbitrum.io/rpc',
|
|
80
|
-
relayerUrl: 'https://next-arbitrum-one-relayer.sequence.app',
|
|
81
|
-
apiUrl: 'https://api.immutable.com',
|
|
82
|
-
name: 'Arbitrum One',
|
|
83
|
-
sequenceIdentityInstrumentEndpoint: 'https://sequence.immutable.com',
|
|
84
|
-
};
|
|
85
|
-
|
|
86
64
|
// Create a mock getUser function for tests
|
|
87
65
|
const createGetUserMock = () => jest.fn().mockResolvedValue({
|
|
88
66
|
profile: { sub: 'user' },
|
|
@@ -121,13 +99,12 @@ describe('connectWallet', () => {
|
|
|
121
99
|
await connectWallet({ getUser, chains: [zkEvmChain] });
|
|
122
100
|
|
|
123
101
|
expect(ZkEvmProvider).toHaveBeenCalled();
|
|
124
|
-
expect(SequenceProvider).not.toHaveBeenCalled();
|
|
125
102
|
});
|
|
126
103
|
|
|
127
104
|
it('uses ZkEvmProvider for zkEVM devnet chain', async () => {
|
|
128
105
|
const getUser = createGetUserMock();
|
|
129
106
|
const devChain = {
|
|
130
|
-
chainId:
|
|
107
|
+
chainId: 99999, // unknown chainId
|
|
131
108
|
rpcUrl: 'https://rpc.dev.immutable.com',
|
|
132
109
|
relayerUrl: 'https://relayer.dev.immutable.com',
|
|
133
110
|
apiUrl: 'https://api.dev.immutable.com',
|
|
@@ -139,16 +116,6 @@ describe('connectWallet', () => {
|
|
|
139
116
|
await connectWallet({ getUser, chains: [devChain] });
|
|
140
117
|
|
|
141
118
|
expect(ZkEvmProvider).toHaveBeenCalled();
|
|
142
|
-
expect(SequenceProvider).not.toHaveBeenCalled();
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it('uses SequenceProvider for non-zkEVM chain (Arbitrum)', async () => {
|
|
146
|
-
const getUser = createGetUserMock();
|
|
147
|
-
|
|
148
|
-
await connectWallet({ getUser, chains: [arbitrumChain] });
|
|
149
|
-
|
|
150
|
-
expect(SequenceProvider).toHaveBeenCalled();
|
|
151
|
-
expect(ZkEvmProvider).not.toHaveBeenCalled();
|
|
152
119
|
});
|
|
153
120
|
});
|
|
154
121
|
});
|
package/src/connectWallet.ts
CHANGED
|
@@ -9,21 +9,15 @@ import {
|
|
|
9
9
|
mr,
|
|
10
10
|
} from '@imtbl/generated-clients';
|
|
11
11
|
import { ZkEvmProvider } from './zkEvm/zkEvmProvider';
|
|
12
|
-
import { SequenceProvider } from './sequence/sequenceProvider';
|
|
13
12
|
import {
|
|
14
|
-
ConnectWalletOptions, PassportEventMap, ChainConfig,
|
|
13
|
+
ConnectWalletOptions, PassportEventMap, ChainConfig, GetUserFunction,
|
|
15
14
|
} from './types';
|
|
16
15
|
import { WalletConfiguration } from './config';
|
|
17
16
|
import GuardianClient from './guardian';
|
|
18
17
|
import MagicTEESigner from './magic/magicTEESigner';
|
|
19
18
|
import { announceProvider, passportProviderInfo } from './provider/eip6963';
|
|
20
|
-
import { DEFAULT_CHAINS } from './
|
|
21
|
-
import {
|
|
22
|
-
MAGIC_CONFIG,
|
|
23
|
-
IMMUTABLE_ZKEVM_TESTNET_CHAIN_ID,
|
|
24
|
-
} from './constants';
|
|
25
|
-
import { ChainId } from './network/chains';
|
|
26
|
-
import { createSequenceSigner } from './sequence/signer';
|
|
19
|
+
import { DEFAULT_CHAINS } from './presets';
|
|
20
|
+
import { MAGIC_CONFIG, IMMUTABLE_ZKEVM_TESTNET_CHAIN_ID } from './constants';
|
|
27
21
|
|
|
28
22
|
/**
|
|
29
23
|
* Type guard to check if chainId is a valid key for MAGIC_CONFIG
|
|
@@ -71,16 +65,6 @@ const DEFAULT_REDIRECT_FALLBACK = 'https://auth.immutable.com/im-logged-in';
|
|
|
71
65
|
const DEFAULT_AUTHENTICATION_DOMAIN = 'https://auth.immutable.com';
|
|
72
66
|
const SANDBOX_DOMAIN_REGEX = /(sandbox|testnet)/i;
|
|
73
67
|
|
|
74
|
-
const ZKEVM_CHAIN_IDS = [
|
|
75
|
-
ChainId.IMTBL_ZKEVM_MAINNET,
|
|
76
|
-
ChainId.IMTBL_ZKEVM_TESTNET,
|
|
77
|
-
ChainId.IMTBL_ZKEVM_DEVNET,
|
|
78
|
-
];
|
|
79
|
-
|
|
80
|
-
function isZkEvmChain(chain: ChainConfig): boolean {
|
|
81
|
-
return ZKEVM_CHAIN_IDS.includes(chain.chainId);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
68
|
function isSandboxChain(chain: ChainConfig): boolean {
|
|
85
69
|
if (chain.chainId === IMMUTABLE_ZKEVM_TESTNET_CHAIN_ID) {
|
|
86
70
|
return true;
|
|
@@ -199,7 +183,7 @@ function createDefaultGetUser(initialChain: ChainConfig, options: ConnectWalletO
|
|
|
199
183
|
*/
|
|
200
184
|
export async function connectWallet(
|
|
201
185
|
config: ConnectWalletOptions = {},
|
|
202
|
-
): Promise<
|
|
186
|
+
): Promise<ZkEvmProvider> {
|
|
203
187
|
// Use default chains if not provided (testnet + mainnet)
|
|
204
188
|
const chains = config.chains && config.chains.length > 0
|
|
205
189
|
? config.chains
|
|
@@ -268,70 +252,45 @@ export async function connectWallet(
|
|
|
268
252
|
clientId,
|
|
269
253
|
});
|
|
270
254
|
|
|
271
|
-
//
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
if (isZkEvmChain(initialChain)) {
|
|
275
|
-
// 9. Get Magic config for initial chain (from chain config or hard-coded default)
|
|
276
|
-
const magicConfig = getMagicConfigForChain(initialChain);
|
|
277
|
-
|
|
278
|
-
// 10. Create MagicTEESigner with Magic TEE base path (separate from backend API)
|
|
279
|
-
const magicTeeBasePath = initialChain.magicTeeBasePath || 'https://tee.express.magiclabs.com';
|
|
280
|
-
const magicTeeApiClients = new MagicTeeApiClients({
|
|
281
|
-
basePath: magicTeeBasePath,
|
|
282
|
-
timeout: 10000,
|
|
283
|
-
magicPublishableApiKey: magicConfig.magicPublishableApiKey,
|
|
284
|
-
magicProviderId: magicConfig.magicProviderId,
|
|
285
|
-
});
|
|
286
|
-
const ethSigner = new MagicTEESigner(getUser, magicTeeApiClients);
|
|
287
|
-
|
|
288
|
-
// 11. Determine session activity API URL (only for mainnet, testnet, devnet)
|
|
289
|
-
let sessionActivityApiUrl: string | null = null;
|
|
290
|
-
if (initialChain.chainId === 13371) {
|
|
291
|
-
// Mainnet
|
|
292
|
-
sessionActivityApiUrl = 'https://api.immutable.com';
|
|
293
|
-
} else if (initialChain.chainId === 13473) {
|
|
294
|
-
// Testnet
|
|
295
|
-
sessionActivityApiUrl = 'https://api.sandbox.immutable.com';
|
|
296
|
-
} else if (initialChain.apiUrl) {
|
|
297
|
-
// Devnet - use the apiUrl from chain config
|
|
298
|
-
sessionActivityApiUrl = initialChain.apiUrl;
|
|
299
|
-
}
|
|
300
|
-
// For any other chain, sessionActivityApiUrl remains null (no session activity tracking)
|
|
301
|
-
|
|
302
|
-
// 12. Create ZkEvmProvider
|
|
303
|
-
provider = new ZkEvmProvider({
|
|
304
|
-
getUser,
|
|
305
|
-
clientId,
|
|
306
|
-
config: walletConfig,
|
|
307
|
-
multiRollupApiClients,
|
|
308
|
-
walletEventEmitter: passportEventEmitter,
|
|
309
|
-
guardianClient,
|
|
310
|
-
ethSigner,
|
|
311
|
-
user,
|
|
312
|
-
sessionActivityApiUrl,
|
|
313
|
-
});
|
|
314
|
-
} else {
|
|
315
|
-
// Determine if this is a dev environment based on domain
|
|
316
|
-
const isDevEnvironment = passportDomain.includes('.dev.') || initialChain.apiUrl.includes('.dev.');
|
|
255
|
+
// 9. Get Magic config for initial chain (from chain config or hard-coded default)
|
|
256
|
+
const magicConfig = getMagicConfigForChain(initialChain);
|
|
317
257
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
258
|
+
// 10. Create MagicTEESigner with Magic TEE base path (separate from backend API)
|
|
259
|
+
const magicTeeBasePath = initialChain.magicTeeBasePath || 'https://tee.express.magiclabs.com';
|
|
260
|
+
const magicTeeApiClients = new MagicTeeApiClients({
|
|
261
|
+
basePath: magicTeeBasePath,
|
|
262
|
+
timeout: 10000,
|
|
263
|
+
magicPublishableApiKey: magicConfig.magicPublishableApiKey,
|
|
264
|
+
magicProviderId: magicConfig.magicProviderId,
|
|
265
|
+
});
|
|
266
|
+
const ethSigner = new MagicTEESigner(getUser, magicTeeApiClients);
|
|
267
|
+
|
|
268
|
+
// 11. Determine session activity API URL (only for mainnet, testnet, devnet)
|
|
269
|
+
let sessionActivityApiUrl: string | null = null;
|
|
270
|
+
if (initialChain.chainId === 13371) {
|
|
271
|
+
// Mainnet
|
|
272
|
+
sessionActivityApiUrl = 'https://api.immutable.com';
|
|
273
|
+
} else if (initialChain.chainId === 13473) {
|
|
274
|
+
// Testnet
|
|
275
|
+
sessionActivityApiUrl = 'https://api.sandbox.immutable.com';
|
|
276
|
+
} else if (initialChain.apiUrl) {
|
|
277
|
+
// Devnet - use the apiUrl from chain config
|
|
278
|
+
sessionActivityApiUrl = initialChain.apiUrl;
|
|
333
279
|
}
|
|
334
280
|
|
|
281
|
+
// 12. Create provider
|
|
282
|
+
const provider = new ZkEvmProvider({
|
|
283
|
+
getUser,
|
|
284
|
+
clientId,
|
|
285
|
+
config: walletConfig,
|
|
286
|
+
multiRollupApiClients,
|
|
287
|
+
walletEventEmitter: passportEventEmitter,
|
|
288
|
+
guardianClient,
|
|
289
|
+
ethSigner,
|
|
290
|
+
user,
|
|
291
|
+
sessionActivityApiUrl,
|
|
292
|
+
});
|
|
293
|
+
|
|
335
294
|
// 13. Announce provider via EIP-6963
|
|
336
295
|
if (config.announceProvider !== false) {
|
|
337
296
|
announceProvider({
|
package/src/constants.ts
CHANGED
|
@@ -8,19 +8,6 @@ export const IMMUTABLE_ZKEVM_MAINNET_CHAIN_ID = 13371;
|
|
|
8
8
|
/** Immutable zkEVM Testnet chain ID */
|
|
9
9
|
export const IMMUTABLE_ZKEVM_TESTNET_CHAIN_ID = 13473;
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
* Chain ID constants for Arbitrum networks
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/** Arbitrum One Mainnet chain ID */
|
|
16
|
-
export const ARBITRUM_ONE_CHAIN_ID = 42161;
|
|
17
|
-
|
|
18
|
-
/** Arbitrum Sepolia Testnet chain ID */
|
|
19
|
-
export const ARBITRUM_SEPOLIA_CHAIN_ID = 421614;
|
|
20
|
-
|
|
21
|
-
/** Ethereum Sepolia Testnet chain ID */
|
|
22
|
-
export const ETHEREUM_SEPOLIA_CHAIN_ID = 11155111;
|
|
23
|
-
|
|
24
11
|
/**
|
|
25
12
|
* Magic configuration for Immutable networks
|
|
26
13
|
* @internal
|
package/src/guardian/index.ts
CHANGED
|
@@ -253,7 +253,6 @@ export default class GuardianClient {
|
|
|
253
253
|
messageId,
|
|
254
254
|
user.zkEvm.ethAddress,
|
|
255
255
|
'eip712',
|
|
256
|
-
chainID,
|
|
257
256
|
);
|
|
258
257
|
|
|
259
258
|
if (!confirmationResult.confirmed) {
|
|
@@ -302,7 +301,6 @@ export default class GuardianClient {
|
|
|
302
301
|
messageId,
|
|
303
302
|
user.zkEvm.ethAddress,
|
|
304
303
|
'erc191',
|
|
305
|
-
String(chainID),
|
|
306
304
|
);
|
|
307
305
|
|
|
308
306
|
if (!confirmationResult.confirmed) {
|
package/src/index.ts
CHANGED
|
@@ -5,36 +5,20 @@ export { connectWallet } from './connectWallet';
|
|
|
5
5
|
export {
|
|
6
6
|
IMMUTABLE_ZKEVM_MAINNET_CHAIN_ID,
|
|
7
7
|
IMMUTABLE_ZKEVM_TESTNET_CHAIN_ID,
|
|
8
|
-
ARBITRUM_ONE_CHAIN_ID,
|
|
9
|
-
ARBITRUM_SEPOLIA_CHAIN_ID,
|
|
10
|
-
ETHEREUM_SEPOLIA_CHAIN_ID,
|
|
11
8
|
} from './constants';
|
|
12
9
|
|
|
13
10
|
// Export presets (public API)
|
|
14
11
|
export {
|
|
15
|
-
// zkEVM chains
|
|
16
12
|
IMMUTABLE_ZKEVM_MAINNET,
|
|
17
13
|
IMMUTABLE_ZKEVM_TESTNET,
|
|
18
14
|
IMMUTABLE_ZKEVM_MULTICHAIN,
|
|
19
15
|
IMMUTABLE_ZKEVM_MAINNET_CHAIN,
|
|
20
16
|
IMMUTABLE_ZKEVM_TESTNET_CHAIN,
|
|
21
17
|
DEFAULT_CHAINS,
|
|
22
|
-
|
|
23
|
-
ARBITRUM_ONE,
|
|
24
|
-
ARBITRUM_SEPOLIA,
|
|
25
|
-
ARBITRUM_ONE_CHAIN,
|
|
26
|
-
ARBITRUM_SEPOLIA_CHAIN,
|
|
27
|
-
// Ethereum chains
|
|
28
|
-
ETHEREUM_SEPOLIA,
|
|
29
|
-
ETHEREUM_SEPOLIA_CHAIN,
|
|
30
|
-
} from './network/presets';
|
|
18
|
+
} from './presets';
|
|
31
19
|
|
|
32
|
-
// Export
|
|
33
|
-
export { getChainConfig, getEvmChainFromChainId } from './network/chainRegistry';
|
|
34
|
-
|
|
35
|
-
// Export main wallet providers
|
|
20
|
+
// Export main wallet provider
|
|
36
21
|
export { ZkEvmProvider } from './zkEvm/zkEvmProvider';
|
|
37
|
-
export { SequenceProvider } from './sequence/sequenceProvider';
|
|
38
22
|
|
|
39
23
|
// Export internal configuration (for Passport/advanced usage)
|
|
40
24
|
export { WalletConfiguration } from './config';
|
package/src/presets.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { ChainConfig } from './types';
|
|
2
|
+
import {
|
|
3
|
+
IMMUTABLE_ZKEVM_MAINNET_CHAIN_ID,
|
|
4
|
+
IMMUTABLE_ZKEVM_TESTNET_CHAIN_ID,
|
|
5
|
+
MAGIC_CONFIG,
|
|
6
|
+
} from './constants';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Immutable zkEVM Mainnet chain configuration
|
|
10
|
+
*/
|
|
11
|
+
export const IMMUTABLE_ZKEVM_MAINNET_CHAIN: ChainConfig = {
|
|
12
|
+
chainId: IMMUTABLE_ZKEVM_MAINNET_CHAIN_ID,
|
|
13
|
+
name: 'Immutable zkEVM',
|
|
14
|
+
rpcUrl: 'https://rpc.immutable.com',
|
|
15
|
+
relayerUrl: 'https://api.immutable.com/relayer-mr',
|
|
16
|
+
apiUrl: 'https://api.immutable.com',
|
|
17
|
+
passportDomain: 'https://passport.immutable.com',
|
|
18
|
+
magicPublishableApiKey: MAGIC_CONFIG[IMMUTABLE_ZKEVM_MAINNET_CHAIN_ID].magicPublishableApiKey,
|
|
19
|
+
magicProviderId: MAGIC_CONFIG[IMMUTABLE_ZKEVM_MAINNET_CHAIN_ID].magicProviderId,
|
|
20
|
+
magicTeeBasePath: 'https://tee.express.magiclabs.com',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Immutable zkEVM Testnet chain configuration
|
|
25
|
+
*/
|
|
26
|
+
export const IMMUTABLE_ZKEVM_TESTNET_CHAIN: ChainConfig = {
|
|
27
|
+
chainId: IMMUTABLE_ZKEVM_TESTNET_CHAIN_ID,
|
|
28
|
+
name: 'Immutable zkEVM Testnet',
|
|
29
|
+
rpcUrl: 'https://rpc.testnet.immutable.com',
|
|
30
|
+
relayerUrl: 'https://api.sandbox.immutable.com/relayer-mr',
|
|
31
|
+
apiUrl: 'https://api.sandbox.immutable.com',
|
|
32
|
+
passportDomain: 'https://passport.sandbox.immutable.com',
|
|
33
|
+
magicPublishableApiKey: MAGIC_CONFIG[IMMUTABLE_ZKEVM_TESTNET_CHAIN_ID].magicPublishableApiKey,
|
|
34
|
+
magicProviderId: MAGIC_CONFIG[IMMUTABLE_ZKEVM_TESTNET_CHAIN_ID].magicProviderId,
|
|
35
|
+
magicTeeBasePath: 'https://tee.express.magiclabs.com',
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Default chains (testnet + mainnet)
|
|
40
|
+
* Testnet is first (default initial chain)
|
|
41
|
+
*/
|
|
42
|
+
export const DEFAULT_CHAINS: ChainConfig[] = [
|
|
43
|
+
IMMUTABLE_ZKEVM_TESTNET_CHAIN,
|
|
44
|
+
IMMUTABLE_ZKEVM_MAINNET_CHAIN,
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Mainnet only preset
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const provider = await connectWallet({
|
|
53
|
+
* ...IMMUTABLE_ZKEVM_MAINNET,
|
|
54
|
+
* auth,
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export const IMMUTABLE_ZKEVM_MAINNET = {
|
|
59
|
+
chains: [IMMUTABLE_ZKEVM_MAINNET_CHAIN],
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Testnet only preset
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const provider = await connectWallet({
|
|
68
|
+
* ...IMMUTABLE_ZKEVM_TESTNET,
|
|
69
|
+
* auth,
|
|
70
|
+
* });
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export const IMMUTABLE_ZKEVM_TESTNET = {
|
|
74
|
+
chains: [IMMUTABLE_ZKEVM_TESTNET_CHAIN],
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Multi-chain preset (testnet + mainnet)
|
|
79
|
+
* Defaults to testnet as initial chain
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const provider = await connectWallet({
|
|
84
|
+
* ...IMMUTABLE_ZKEVM_MULTICHAIN,
|
|
85
|
+
* auth,
|
|
86
|
+
* initialChainId: IMMUTABLE_ZKEVM_MAINNET_CHAIN_ID, // Optional: start on mainnet
|
|
87
|
+
* });
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export const IMMUTABLE_ZKEVM_MULTICHAIN = {
|
|
91
|
+
chains: DEFAULT_CHAINS,
|
|
92
|
+
};
|