@imtbl/wallet 2.12.7-alpha.1 → 2.12.7-alpha.11
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 +464 -58
- 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
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
|
+
};
|
package/src/types.ts
CHANGED
|
@@ -2,11 +2,6 @@ import { Flow } from '@imtbl/metrics';
|
|
|
2
2
|
import { TypedEventEmitter, User } from '@imtbl/auth';
|
|
3
3
|
import { JsonRpcError } from './zkEvm/JsonRpcError';
|
|
4
4
|
|
|
5
|
-
export enum EvmChain {
|
|
6
|
-
ZKEVM = 'zkevm',
|
|
7
|
-
ARBITRUM_ONE = 'arbitrum_one',
|
|
8
|
-
}
|
|
9
|
-
|
|
10
5
|
/**
|
|
11
6
|
* A viem-compatible signer interface for wallet operations.
|
|
12
7
|
* This replaces ethers' AbstractSigner/Signer.
|
|
@@ -206,17 +201,6 @@ export interface ChainConfig {
|
|
|
206
201
|
* Defaults to 'https://tee.express.magiclabs.com'
|
|
207
202
|
*/
|
|
208
203
|
magicTeeBasePath?: string;
|
|
209
|
-
|
|
210
|
-
/** Preferred token symbol for relayer fees (default: 'IMX') */
|
|
211
|
-
feeTokenSymbol?: string;
|
|
212
|
-
|
|
213
|
-
/** Sequence RPC node URL TODO: check if this can be removed and only use rpcUrl */
|
|
214
|
-
nodeUrl?: string;
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Sequence Identity Instrument endpoint (for non-zkEVM chains in prod/sandbox)
|
|
218
|
-
*/
|
|
219
|
-
sequenceIdentityInstrumentEndpoint?: string;
|
|
220
204
|
}
|
|
221
205
|
|
|
222
206
|
/**
|
package/src/zkEvm/types.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { JsonRpcError } from './JsonRpcError';
|
|
2
|
-
import type { Provider as ProviderType } from '../types';
|
|
3
2
|
|
|
4
3
|
export enum RelayerTransactionStatus {
|
|
5
4
|
PENDING = 'PENDING',
|
|
@@ -92,9 +91,16 @@ export interface JsonRpcResponsePayload {
|
|
|
92
91
|
id?: string | number;
|
|
93
92
|
}
|
|
94
93
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
/**
|
|
95
|
+
* EIP-1193 Provider Interface
|
|
96
|
+
* Standard Ethereum provider interface
|
|
97
|
+
*/
|
|
98
|
+
export type Provider = {
|
|
99
|
+
request: (request: RequestArguments) => Promise<any>;
|
|
100
|
+
on: (event: string, listener: (...args: any[]) => void) => void;
|
|
101
|
+
removeListener: (event: string, listener: (...args: any[]) => void) => void;
|
|
102
|
+
isPassport: boolean;
|
|
103
|
+
};
|
|
98
104
|
|
|
99
105
|
export enum ProviderEvent {
|
|
100
106
|
ACCOUNTS_CHANGED = 'accountsChanged',
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Environment } from '@imtbl/config';
|
|
2
|
-
import { ChainConfig, EvmChain } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* Get chain config for non-zkEVM chains
|
|
5
|
-
* @throws Error if chain is not in registry
|
|
6
|
-
*/
|
|
7
|
-
export declare function getChainConfig(chain: Exclude<EvmChain, EvmChain.ZKEVM>, environment: Environment): ChainConfig;
|
|
8
|
-
/**
|
|
9
|
-
* Get EvmChain from chainId
|
|
10
|
-
* @param chainId - Chain ID (can be number or string like "eip155:42161")
|
|
11
|
-
* @returns EvmChain enum value, defaults to ZKEVM if not found
|
|
12
|
-
*/
|
|
13
|
-
export declare function getEvmChainFromChainId(chainId: string | number): EvmChain;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { MultiRollupApiClients } from '@imtbl/generated-clients';
|
|
2
|
-
import { TypedEventEmitter } from '@imtbl/auth';
|
|
3
|
-
import { Provider, ProviderEventMap, RequestArguments, ChainConfig, GetUserFunction } from '../types';
|
|
4
|
-
import GuardianClient from '../guardian';
|
|
5
|
-
import { SequenceSigner } from './signer';
|
|
6
|
-
export type SequenceProviderInput = {
|
|
7
|
-
getUser: GetUserFunction;
|
|
8
|
-
chainConfig: ChainConfig;
|
|
9
|
-
multiRollupApiClients: MultiRollupApiClients;
|
|
10
|
-
guardianClient: GuardianClient;
|
|
11
|
-
ethSigner: SequenceSigner;
|
|
12
|
-
passportEventEmitter: TypedEventEmitter<ProviderEventMap>;
|
|
13
|
-
};
|
|
14
|
-
export declare class SequenceProvider implements Provider {
|
|
15
|
-
#private;
|
|
16
|
-
readonly isPassport: boolean;
|
|
17
|
-
constructor({ getUser, chainConfig, multiRollupApiClients, guardianClient, ethSigner, passportEventEmitter, }: SequenceProviderInput);
|
|
18
|
-
request(request: RequestArguments): Promise<any>;
|
|
19
|
-
on(event: string, listener: (...args: any[]) => void): void;
|
|
20
|
-
removeListener(event: string, listener: (...args: any[]) => void): void;
|
|
21
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Address } from 'ox';
|
|
2
|
-
import { Payload, Signature as SequenceSignature } from '@0xsequence/wallet-primitives';
|
|
3
|
-
import { SequenceSigner } from './types';
|
|
4
|
-
import { GetUserFunction } from '../../types';
|
|
5
|
-
export interface IdentityInstrumentSignerConfig {
|
|
6
|
-
/** Sequence Identity Instrument endpoint URL */
|
|
7
|
-
identityInstrumentEndpoint: string;
|
|
8
|
-
}
|
|
9
|
-
export declare class IdentityInstrumentSigner implements SequenceSigner {
|
|
10
|
-
#private;
|
|
11
|
-
constructor(getUser: GetUserFunction, config: IdentityInstrumentSignerConfig);
|
|
12
|
-
getAddress(): Promise<string>;
|
|
13
|
-
signPayload(walletAddress: Address.Address, chainId: number, payload: Payload.Parented): Promise<SequenceSignature.SignatureOfSignerLeaf>;
|
|
14
|
-
signMessage(message: string | Uint8Array): Promise<string>;
|
|
15
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { SequenceSigner } from './types';
|
|
2
|
-
import { GetUserFunction } from '../../types';
|
|
3
|
-
export type { SequenceSigner } from './types';
|
|
4
|
-
export { IdentityInstrumentSigner } from './identityInstrumentSigner';
|
|
5
|
-
export type { IdentityInstrumentSignerConfig } from './identityInstrumentSigner';
|
|
6
|
-
export { PrivateKeySigner } from './privateKeySigner';
|
|
7
|
-
export interface CreateSequenceSignerConfig {
|
|
8
|
-
/** Identity Instrument endpoint (required for prod/sandbox) */
|
|
9
|
-
identityInstrumentEndpoint?: string;
|
|
10
|
-
/** Whether this is a dev environment (uses PrivateKeySigner instead of IdentityInstrumentSigner) */
|
|
11
|
-
isDevEnvironment?: boolean;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Create the appropriate signer based on environment.
|
|
15
|
-
* - Dev environment (behind VPN): uses PrivateKeySigner
|
|
16
|
-
* - Prod/Sandbox: uses IdentityInstrumentSigner
|
|
17
|
-
*
|
|
18
|
-
* @param getUser - Function to get the current user
|
|
19
|
-
* @param config - Signer configuration
|
|
20
|
-
*/
|
|
21
|
-
export declare function createSequenceSigner(getUser: GetUserFunction, config?: CreateSequenceSignerConfig): SequenceSigner;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Payload, Signature as SequenceSignature } from '@0xsequence/wallet-primitives';
|
|
2
|
-
import { SequenceSigner } from './types';
|
|
3
|
-
import { Address } from 'ox';
|
|
4
|
-
import { GetUserFunction } from '../../types';
|
|
5
|
-
/**
|
|
6
|
-
* Private key signer for dev environments (behind VPN).
|
|
7
|
-
* Uses a deterministic private key derived from the user's sub.
|
|
8
|
-
*/
|
|
9
|
-
export declare class PrivateKeySigner implements SequenceSigner {
|
|
10
|
-
#private;
|
|
11
|
-
constructor(getUser: GetUserFunction);
|
|
12
|
-
getAddress(): Promise<string>;
|
|
13
|
-
signPayload(walletAddress: Address.Address, chainId: number, payload: Payload.Parented): Promise<SequenceSignature.SignatureOfSignerLeaf>;
|
|
14
|
-
signMessage(message: string | Uint8Array): Promise<string>;
|
|
15
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Address } from 'ox';
|
|
2
|
-
import { Payload, Signature as SequenceSignature } from '@0xsequence/wallet-primitives';
|
|
3
|
-
/**
|
|
4
|
-
* Signer interface for Sequence wallet operations.
|
|
5
|
-
* Used by non-zkEVM chains (e.g., Arbitrum).
|
|
6
|
-
*/
|
|
7
|
-
export interface SequenceSigner {
|
|
8
|
-
/** Get the signer's address */
|
|
9
|
-
getAddress(): Promise<string>;
|
|
10
|
-
/** Sign a Sequence payload (for transactions) */
|
|
11
|
-
signPayload(walletAddress: Address.Address, chainId: number, payload: Payload.Parented): Promise<SequenceSignature.SignatureOfSignerLeaf>;
|
|
12
|
-
/** Sign a message (EIP-191 personal_sign) */
|
|
13
|
-
signMessage(message: string | Uint8Array): Promise<string>;
|
|
14
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { MultiRollupApiClients } from '@imtbl/generated-clients';
|
|
2
|
-
import { Flow } from '@imtbl/metrics';
|
|
3
|
-
import type { PublicClient } from 'viem';
|
|
4
|
-
import { SequenceSigner } from '../signer';
|
|
5
|
-
import { GetUserFunction } from '../../types';
|
|
6
|
-
export type RegisterUserInput = {
|
|
7
|
-
getUser: GetUserFunction;
|
|
8
|
-
ethSigner: SequenceSigner;
|
|
9
|
-
multiRollupApiClients: MultiRollupApiClients;
|
|
10
|
-
accessToken: string;
|
|
11
|
-
rpcProvider: PublicClient;
|
|
12
|
-
flow: Flow;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Register a user for a non-zkEVM chain (e.g., Arbitrum).
|
|
16
|
-
* Creates a counterfactual address for the user on the specified chain.
|
|
17
|
-
*/
|
|
18
|
-
export declare function registerUser({ getUser, ethSigner, multiRollupApiClients, accessToken, rpcProvider, flow, }: RegisterUserInput): Promise<string>;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { Environment } from '@imtbl/config';
|
|
2
|
-
import { getChainConfig, getEvmChainFromChainId } from './chainRegistry';
|
|
3
|
-
import { EvmChain } from '../types';
|
|
4
|
-
import { ARBITRUM_ONE_CHAIN, ETHEREUM_SEPOLIA_CHAIN } from './presets';
|
|
5
|
-
|
|
6
|
-
describe('chainRegistry', () => {
|
|
7
|
-
describe('getChainConfig', () => {
|
|
8
|
-
it('returns Arbitrum One mainnet config for PRODUCTION', () => {
|
|
9
|
-
const config = getChainConfig(EvmChain.ARBITRUM_ONE, Environment.PRODUCTION);
|
|
10
|
-
|
|
11
|
-
expect(config).toEqual(ARBITRUM_ONE_CHAIN);
|
|
12
|
-
expect(config.chainId).toBe(42161);
|
|
13
|
-
expect(config.name).toBe('Arbitrum One');
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('returns Ethereum Sepolia config for SANDBOX', () => {
|
|
17
|
-
const config = getChainConfig(EvmChain.ARBITRUM_ONE, Environment.SANDBOX);
|
|
18
|
-
|
|
19
|
-
expect(config).toEqual(ETHEREUM_SEPOLIA_CHAIN);
|
|
20
|
-
expect(config.chainId).toBe(11155111);
|
|
21
|
-
expect(config.name).toBe('Ethereum Sepolia');
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('throws error for unsupported chain', () => {
|
|
25
|
-
expect(() => {
|
|
26
|
-
getChainConfig('unsupported_chain' as any, Environment.PRODUCTION);
|
|
27
|
-
}).toThrow('Chain unsupported_chain is not supported');
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
describe('getEvmChainFromChainId', () => {
|
|
32
|
-
it('returns ZKEVM for mainnet chainId', () => {
|
|
33
|
-
expect(getEvmChainFromChainId(13371)).toBe(EvmChain.ZKEVM);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('returns ZKEVM for testnet chainId', () => {
|
|
37
|
-
expect(getEvmChainFromChainId(13473)).toBe(EvmChain.ZKEVM);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('returns ZKEVM for devnet chainId', () => {
|
|
41
|
-
expect(getEvmChainFromChainId(15003)).toBe(EvmChain.ZKEVM);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('returns ARBITRUM_ONE for Arbitrum mainnet chainId', () => {
|
|
45
|
-
expect(getEvmChainFromChainId(42161)).toBe(EvmChain.ARBITRUM_ONE);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('returns ARBITRUM_ONE for Ethereum Sepolia chainId', () => {
|
|
49
|
-
expect(getEvmChainFromChainId(11155111)).toBe(EvmChain.ARBITRUM_ONE);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('handles string chainId', () => {
|
|
53
|
-
expect(getEvmChainFromChainId('42161')).toBe(EvmChain.ARBITRUM_ONE);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('handles eip155 format chainId', () => {
|
|
57
|
-
expect(getEvmChainFromChainId('eip155:42161')).toBe(EvmChain.ARBITRUM_ONE);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('defaults to ZKEVM for unknown chainId', () => {
|
|
61
|
-
expect(getEvmChainFromChainId(99999)).toBe(EvmChain.ZKEVM);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
});
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { Environment } from '@imtbl/config';
|
|
2
|
-
import { ChainConfig, EvmChain } from '../types';
|
|
3
|
-
import {
|
|
4
|
-
IMMUTABLE_ZKEVM_MAINNET_CHAIN,
|
|
5
|
-
IMMUTABLE_ZKEVM_TESTNET_CHAIN,
|
|
6
|
-
ARBITRUM_ONE_CHAIN,
|
|
7
|
-
ETHEREUM_SEPOLIA_CHAIN,
|
|
8
|
-
} from './presets';
|
|
9
|
-
import { ChainId } from './chains';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Registry mapping (EvmChain, Environment) to ChainConfig
|
|
13
|
-
*/
|
|
14
|
-
const CHAIN_REGISTRY: Record<EvmChain, Record<Environment, ChainConfig>> = {
|
|
15
|
-
[EvmChain.ZKEVM]: {
|
|
16
|
-
[Environment.PRODUCTION]: IMMUTABLE_ZKEVM_MAINNET_CHAIN,
|
|
17
|
-
[Environment.SANDBOX]: IMMUTABLE_ZKEVM_TESTNET_CHAIN,
|
|
18
|
-
},
|
|
19
|
-
[EvmChain.ARBITRUM_ONE]: {
|
|
20
|
-
[Environment.PRODUCTION]: ARBITRUM_ONE_CHAIN,
|
|
21
|
-
[Environment.SANDBOX]: ETHEREUM_SEPOLIA_CHAIN,
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Build chainId → EvmChain mapping from CHAIN_REGISTRY (derived, not manual)
|
|
27
|
-
*/
|
|
28
|
-
function buildChainIdToEvmChainMap(): Record<number, EvmChain> {
|
|
29
|
-
const map: Record<number, EvmChain> = {};
|
|
30
|
-
for (const [evmChain, envConfigs] of Object.entries(CHAIN_REGISTRY)) {
|
|
31
|
-
for (const config of Object.values(envConfigs)) {
|
|
32
|
-
map[config.chainId] = evmChain as EvmChain;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
// Devnet doesn't have a preset
|
|
36
|
-
map[ChainId.IMTBL_ZKEVM_DEVNET] = EvmChain.ZKEVM;
|
|
37
|
-
return map;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const CHAIN_ID_TO_EVM_CHAIN = buildChainIdToEvmChainMap();
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Get chain config for non-zkEVM chains
|
|
44
|
-
* @throws Error if chain is not in registry
|
|
45
|
-
*/
|
|
46
|
-
export function getChainConfig(
|
|
47
|
-
chain: Exclude<EvmChain, EvmChain.ZKEVM>,
|
|
48
|
-
environment: Environment,
|
|
49
|
-
): ChainConfig {
|
|
50
|
-
const envConfigs = CHAIN_REGISTRY[chain];
|
|
51
|
-
if (!envConfigs) {
|
|
52
|
-
throw new Error(`Chain ${chain} is not supported`);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const config = envConfigs[environment];
|
|
56
|
-
if (!config) {
|
|
57
|
-
throw new Error(`Chain ${chain} is not configured for environment ${environment}`);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return config;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Get EvmChain from chainId
|
|
65
|
-
* @param chainId - Chain ID (can be number or string like "eip155:42161")
|
|
66
|
-
* @returns EvmChain enum value, defaults to ZKEVM if not found
|
|
67
|
-
*/
|
|
68
|
-
export function getEvmChainFromChainId(chainId: string | number): EvmChain {
|
|
69
|
-
const numericChainId = typeof chainId === 'string'
|
|
70
|
-
? parseInt(chainId.includes(':') ? chainId.split(':')[1] : chainId, 10)
|
|
71
|
-
: chainId;
|
|
72
|
-
|
|
73
|
-
return CHAIN_ID_TO_EVM_CHAIN[numericChainId] ?? EvmChain.ZKEVM;
|
|
74
|
-
}
|