@imtbl/wallet 2.10.7-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/.eslintrc.cjs +18 -0
  2. package/LICENSE.md +176 -0
  3. package/dist/browser/index.mjs +21 -0
  4. package/dist/node/index.js +71 -0
  5. package/dist/node/index.mjs +22 -0
  6. package/dist/types/config.d.ts +13 -0
  7. package/dist/types/errors.d.ts +14 -0
  8. package/dist/types/guardian/index.d.ts +57 -0
  9. package/dist/types/index.d.ts +12 -0
  10. package/dist/types/magic/index.d.ts +1 -0
  11. package/dist/types/magic/magicTEESigner.d.ts +24 -0
  12. package/dist/types/network/chains.d.ts +32 -0
  13. package/dist/types/network/constants.d.ts +3 -0
  14. package/dist/types/network/retry.d.ts +8 -0
  15. package/dist/types/provider/eip6963.d.ts +3 -0
  16. package/dist/types/types.d.ts +163 -0
  17. package/dist/types/utils/metrics.d.ts +3 -0
  18. package/dist/types/utils/string.d.ts +1 -0
  19. package/dist/types/utils/typedEventEmitter.d.ts +6 -0
  20. package/dist/types/zkEvm/JsonRpcError.d.ts +25 -0
  21. package/dist/types/zkEvm/index.d.ts +2 -0
  22. package/dist/types/zkEvm/personalSign.d.ts +15 -0
  23. package/dist/types/zkEvm/provider/eip6963.d.ts +3 -0
  24. package/dist/types/zkEvm/relayerClient.d.ts +60 -0
  25. package/dist/types/zkEvm/sendDeployTransactionAndPersonalSign.d.ts +6 -0
  26. package/dist/types/zkEvm/sendTransaction.d.ts +6 -0
  27. package/dist/types/zkEvm/sessionActivity/errorBoundary.d.ts +1 -0
  28. package/dist/types/zkEvm/sessionActivity/request.d.ts +15 -0
  29. package/dist/types/zkEvm/sessionActivity/sessionActivity.d.ts +2 -0
  30. package/dist/types/zkEvm/signEjectionTransaction.d.ts +6 -0
  31. package/dist/types/zkEvm/signTypedDataV4.d.ts +14 -0
  32. package/dist/types/zkEvm/transactionHelpers.d.ts +31 -0
  33. package/dist/types/zkEvm/types.d.ts +120 -0
  34. package/dist/types/zkEvm/user/index.d.ts +1 -0
  35. package/dist/types/zkEvm/user/registerZkEvmUser.d.ts +13 -0
  36. package/dist/types/zkEvm/walletHelpers.d.ts +33 -0
  37. package/dist/types/zkEvm/zkEvmProvider.d.ts +25 -0
  38. package/package.json +55 -0
  39. package/src/config.ts +51 -0
  40. package/src/errors.ts +33 -0
  41. package/src/guardian/index.ts +358 -0
  42. package/src/index.ts +27 -0
  43. package/src/magic/index.ts +1 -0
  44. package/src/magic/magicTEESigner.ts +214 -0
  45. package/src/network/chains.ts +33 -0
  46. package/src/network/constants.ts +28 -0
  47. package/src/network/retry.ts +37 -0
  48. package/src/provider/eip6963.ts +25 -0
  49. package/src/types.ts +192 -0
  50. package/src/utils/metrics.ts +57 -0
  51. package/src/utils/string.ts +12 -0
  52. package/src/utils/typedEventEmitter.ts +26 -0
  53. package/src/zkEvm/JsonRpcError.ts +33 -0
  54. package/src/zkEvm/index.ts +2 -0
  55. package/src/zkEvm/personalSign.ts +62 -0
  56. package/src/zkEvm/provider/eip6963.ts +25 -0
  57. package/src/zkEvm/relayerClient.ts +216 -0
  58. package/src/zkEvm/sendDeployTransactionAndPersonalSign.ts +44 -0
  59. package/src/zkEvm/sendTransaction.ts +34 -0
  60. package/src/zkEvm/sessionActivity/errorBoundary.ts +33 -0
  61. package/src/zkEvm/sessionActivity/request.ts +62 -0
  62. package/src/zkEvm/sessionActivity/sessionActivity.ts +140 -0
  63. package/src/zkEvm/signEjectionTransaction.ts +33 -0
  64. package/src/zkEvm/signTypedDataV4.ts +103 -0
  65. package/src/zkEvm/transactionHelpers.ts +295 -0
  66. package/src/zkEvm/types.ts +136 -0
  67. package/src/zkEvm/user/index.ts +1 -0
  68. package/src/zkEvm/user/registerZkEvmUser.ts +75 -0
  69. package/src/zkEvm/walletHelpers.ts +243 -0
  70. package/src/zkEvm/zkEvmProvider.ts +453 -0
  71. package/tsconfig.json +15 -0
@@ -0,0 +1,12 @@
1
+ export { ZkEvmProvider } from './zkEvm/zkEvmProvider';
2
+ export { WalletConfiguration } from './config';
3
+ export * from './types';
4
+ export { WalletError, WalletErrorType } from './errors';
5
+ export { JsonRpcError, ProviderErrorCode, RpcErrorCode } from './zkEvm/JsonRpcError';
6
+ export { RelayerClient } from './zkEvm/relayerClient';
7
+ export * as walletHelpers from './zkEvm/walletHelpers';
8
+ export { default as GuardianClient } from './guardian';
9
+ export { default as MagicTEESigner } from './magic/magicTEESigner';
10
+ export { default as TypedEventEmitter } from './utils/typedEventEmitter';
11
+ export { retryWithDelay } from './network/retry';
12
+ export { announceProvider, passportProviderInfo } from './provider/eip6963';
@@ -0,0 +1 @@
1
+ export { default as MagicTEESigner } from './magicTEESigner';
@@ -0,0 +1,24 @@
1
+ import { AbstractSigner, Signer } from 'ethers';
2
+ import { MagicTeeApiClients } from '@imtbl/generated-clients';
3
+ import { AuthManager } from '@imtbl/auth';
4
+ export default class MagicTEESigner extends AbstractSigner {
5
+ private readonly authManager;
6
+ private readonly magicTeeApiClient;
7
+ private userWallet;
8
+ private createWalletPromise;
9
+ constructor(authManager: AuthManager, magicTeeApiClient: MagicTeeApiClients);
10
+ private getUserWallet;
11
+ /**
12
+ * This method calls the createWallet endpoint. The user's wallet must be created before it can be used to sign messages.
13
+ * The createWallet endpoint is idempotent, so it can be called multiple times without causing an error.
14
+ * If a createWallet request is already in flight, return the existing promise.
15
+ */
16
+ private createWallet;
17
+ private getUserOrThrow;
18
+ private static getHeaders;
19
+ getAddress(): Promise<string>;
20
+ signMessage(message: string | Uint8Array): Promise<string>;
21
+ connect(): Signer;
22
+ signTransaction(): Promise<string>;
23
+ signTypedData(): Promise<string>;
24
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Enum representing different chain IDs.
3
+ * @enum {number}
4
+ * @property {number} IMTBL_ZKEVM_MAINNET - The chain ID for IMTBL ZKEVM Mainnet.
5
+ * @property {number} IMTBL_ZKEVM_TESTNET - The chain ID for IMTBL ZKEVM Testnet.
6
+ * @property {number} IMTBL_ZKEVM_DEVNET - The chain ID for IMTBL ZKEVM Devnet.
7
+ * @property {number} ETHEREUM - The chain ID for Ethereum.
8
+ * @property {number} SEPOLIA - The chain ID for Sepolia.
9
+ */
10
+ export declare enum ChainId {
11
+ IMTBL_ZKEVM_MAINNET = 13371,
12
+ IMTBL_ZKEVM_TESTNET = 13473,
13
+ IMTBL_ZKEVM_DEVNET = 15003,
14
+ ETHEREUM = 1,
15
+ SEPOLIA = 11155111
16
+ }
17
+ /**
18
+ * Enum representing different chain names.
19
+ * @enum {number}
20
+ * @property {number} IMTBL_ZKEVM_MAINNET - The chain name for IMTBL ZKEVM Mainnet.
21
+ * @property {number} IMTBL_ZKEVM_TESTNET - The chain name for IMTBL ZKEVM Testnet.
22
+ * @property {number} IMTBL_ZKEVM_DEVNET - The chain name for IMTBL ZKEVM Devnet.
23
+ * @property {number} ETHEREUM - The chain name for Ethereum.
24
+ * @property {number} SEPOLIA - The chain name for Sepolia.
25
+ */
26
+ export declare enum ChainName {
27
+ ETHEREUM = "Ethereum",
28
+ SEPOLIA = "Sepolia",
29
+ IMTBL_ZKEVM_TESTNET = "Immutable zkEVM Test",
30
+ IMTBL_ZKEVM_DEVNET = "Immutable zkEVM Dev",
31
+ IMTBL_ZKEVM_MAINNET = "Immutable zkEVM"
32
+ }
@@ -0,0 +1,3 @@
1
+ import { ChainId, ChainName } from './chains';
2
+ export type ChainMap = Map<ChainId, ChainName>;
3
+ export declare const CHAIN_NAME_MAP: ChainMap;
@@ -0,0 +1,8 @@
1
+ export declare const MAX_RETRIES = 3;
2
+ export type RetryOption = {
3
+ retries?: number;
4
+ interval?: number;
5
+ finalErr?: Error;
6
+ finallyFn?: () => void;
7
+ };
8
+ export declare const retryWithDelay: <T>(fn: () => Promise<T>, options?: RetryOption) => Promise<T>;
@@ -0,0 +1,3 @@
1
+ import { EIP6963ProviderDetail, EIP6963ProviderInfo } from '../types';
2
+ export declare const passportProviderInfo: EIP6963ProviderInfo;
3
+ export declare function announceProvider(detail: EIP6963ProviderDetail): void;
@@ -0,0 +1,163 @@
1
+ import { Environment, ModuleConfiguration } from '@imtbl/config';
2
+ import { Flow } from '@imtbl/metrics';
3
+ import { User } from '@imtbl/auth';
4
+ import { BigNumberish } from 'ethers';
5
+ import { JsonRpcError } from './zkEvm/JsonRpcError';
6
+ export type { User, UserProfile, UserImx, UserZkEvm, DirectLoginMethod, } from '@imtbl/auth';
7
+ export { isUserImx, isUserZkEvm } from '@imtbl/auth';
8
+ export type { RollupType } from '@imtbl/auth';
9
+ export declare enum PassportEvents {
10
+ LOGGED_OUT = "loggedOut",
11
+ LOGGED_IN = "loggedIn",
12
+ ACCOUNTS_REQUESTED = "accountsRequested"
13
+ }
14
+ export type AccountsRequestedEvent = {
15
+ environment: Environment;
16
+ sendTransaction: (params: Array<any>, flow: Flow) => Promise<string>;
17
+ walletAddress: string;
18
+ passportClient: string;
19
+ flow?: Flow;
20
+ };
21
+ export interface PassportEventMap extends Record<string, any> {
22
+ [PassportEvents.LOGGED_OUT]: [];
23
+ [PassportEvents.LOGGED_IN]: [User];
24
+ [PassportEvents.ACCOUNTS_REQUESTED]: [AccountsRequestedEvent];
25
+ }
26
+ export type Provider = {
27
+ request: (request: RequestArguments) => Promise<any>;
28
+ on: (event: string, listener: (...args: any[]) => void) => void;
29
+ removeListener: (event: string, listener: (...args: any[]) => void) => void;
30
+ isPassport: boolean;
31
+ };
32
+ export interface RequestArguments {
33
+ method: string;
34
+ params?: Array<any>;
35
+ }
36
+ export type JsonRpcRequestPayload = RequestArguments & {
37
+ jsonrpc?: string;
38
+ id?: string | number;
39
+ };
40
+ export interface JsonRpcRequestCallback {
41
+ (err: JsonRpcError | null, result?: JsonRpcResponsePayload | (JsonRpcResponsePayload | null)[] | null): void;
42
+ }
43
+ export interface JsonRpcResponsePayload {
44
+ result?: Array<any> | null;
45
+ error?: JsonRpcError | null;
46
+ jsonrpc?: string;
47
+ id?: string | number;
48
+ }
49
+ export interface TypedDataPayload {
50
+ types: {
51
+ EIP712Domain: Array<{
52
+ name: string;
53
+ type: string;
54
+ }>;
55
+ [key: string]: Array<{
56
+ name: string;
57
+ type: string;
58
+ }>;
59
+ };
60
+ domain: {
61
+ name?: string;
62
+ version?: string;
63
+ chainId?: number | string;
64
+ verifyingContract?: string;
65
+ salt?: string;
66
+ } | {
67
+ name?: string;
68
+ version?: string;
69
+ chainId?: number;
70
+ verifyingContract?: string;
71
+ salt?: string;
72
+ };
73
+ primaryType: string;
74
+ message: Record<string, any>;
75
+ }
76
+ export interface MetaTransaction {
77
+ to: string;
78
+ value?: BigNumberish | null;
79
+ data?: string | null;
80
+ nonce?: BigNumberish;
81
+ gasLimit?: BigNumberish;
82
+ delegateCall?: boolean;
83
+ revertOnError?: boolean;
84
+ }
85
+ export interface MetaTransactionNormalised {
86
+ delegateCall: boolean;
87
+ revertOnError: boolean;
88
+ gasLimit: BigNumberish;
89
+ target: string;
90
+ value: BigNumberish;
91
+ data: string;
92
+ }
93
+ export declare enum ProviderEvent {
94
+ ACCOUNTS_CHANGED = "accountsChanged"
95
+ }
96
+ export type AccountsChangedEvent = Array<string>;
97
+ export interface ProviderEventMap extends Record<string, any> {
98
+ [ProviderEvent.ACCOUNTS_CHANGED]: [AccountsChangedEvent];
99
+ }
100
+ export declare enum RelayerTransactionStatus {
101
+ PENDING = "PENDING",
102
+ SUBMITTED = "SUBMITTED",
103
+ SUCCESSFUL = "SUCCESSFUL",
104
+ REVERTED = "REVERTED",
105
+ FAILED = "FAILED",
106
+ CANCELLED = "CANCELLED"
107
+ }
108
+ export interface RelayerTransaction {
109
+ status: RelayerTransactionStatus;
110
+ chainId: string;
111
+ relayerId: string;
112
+ hash: string;
113
+ statusMessage?: string;
114
+ }
115
+ export interface FeeOption {
116
+ tokenPrice: string;
117
+ tokenSymbol: string;
118
+ tokenDecimals: number;
119
+ tokenAddress: string;
120
+ recipientAddress: string;
121
+ }
122
+ /**
123
+ * Event detail from the `eip6963:announceProvider` event.
124
+ */
125
+ export interface EIP6963ProviderDetail {
126
+ info: EIP6963ProviderInfo;
127
+ provider: Provider;
128
+ }
129
+ /**
130
+ * Metadata of the EIP-1193 Provider.
131
+ */
132
+ export interface EIP6963ProviderInfo {
133
+ icon: `data:image/${string}`;
134
+ name: string;
135
+ rdns: string;
136
+ uuid: string;
137
+ }
138
+ /**
139
+ * Event type to announce an EIP-1193 Provider.
140
+ */
141
+ export interface EIP6963AnnounceProviderEvent extends CustomEvent<EIP6963ProviderDetail> {
142
+ type: 'eip6963:announceProvider';
143
+ }
144
+ export interface WalletOverrides {
145
+ passportDomain: string;
146
+ zkEvmRpcUrl: string;
147
+ relayerUrl: string;
148
+ indexerMrBasePath: string;
149
+ }
150
+ export interface WalletModuleConfiguration extends ModuleConfiguration<WalletOverrides> {
151
+ /**
152
+ * Optional referrer URL to be sent with JSON-RPC requests.
153
+ */
154
+ jsonRpcReferrer?: string;
155
+ /**
156
+ * If true, forces SCW deployment before allowing message signature.
157
+ */
158
+ forceScwDeployBeforeMessageSignature?: boolean;
159
+ /**
160
+ * This flag indicates that Wallet is being used in a cross-sdk bridge scenario.
161
+ */
162
+ crossSdkBridgeEnabled?: boolean;
163
+ }
@@ -0,0 +1,3 @@
1
+ import { Flow } from '@imtbl/metrics';
2
+ export declare const withMetrics: <T>(fn: (flow: Flow) => T, flowName: string, trackStartEvent?: boolean, trackEndEvent?: boolean) => T;
3
+ export declare const withMetricsAsync: <T>(fn: (flow: Flow) => Promise<T>, flowName: string, trackStartEvent?: boolean, trackEndEvent?: boolean) => Promise<T>;
@@ -0,0 +1 @@
1
+ export declare const hexToString: (hex: string) => string;
@@ -0,0 +1,6 @@
1
+ export default class TypedEventEmitter<TEvents extends Record<string, any>> {
2
+ private emitter;
3
+ emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArg: TEvents[TEventName]): void;
4
+ on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
5
+ removeListener<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
6
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * ProviderErrors should take priority over RpcErrorCodes
3
+ * https://eips.ethereum.org/EIPS/eip-1193#provider-errors
4
+ * https://eips.ethereum.org/EIPS/eip-1474#error-codes
5
+ */
6
+ export declare enum ProviderErrorCode {
7
+ USER_REJECTED_REQUEST = 4001,
8
+ UNAUTHORIZED = 4100,
9
+ UNSUPPORTED_METHOD = 4200,
10
+ DISCONNECTED = 4900
11
+ }
12
+ export declare enum RpcErrorCode {
13
+ RPC_SERVER_ERROR = -32000,
14
+ INVALID_REQUEST = -32600,
15
+ METHOD_NOT_FOUND = -32601,
16
+ INVALID_PARAMS = -32602,
17
+ INTERNAL_ERROR = -32603,
18
+ PARSE_ERROR = -32700,
19
+ TRANSACTION_REJECTED = -32003
20
+ }
21
+ export declare class JsonRpcError extends Error {
22
+ readonly message: string;
23
+ readonly code: ProviderErrorCode | RpcErrorCode;
24
+ constructor(code: ProviderErrorCode | RpcErrorCode, message: string);
25
+ }
@@ -0,0 +1,2 @@
1
+ export * from './zkEvmProvider';
2
+ export * from './types';
@@ -0,0 +1,15 @@
1
+ import { Flow } from '@imtbl/metrics';
2
+ import { Signer, JsonRpcProvider } from 'ethers';
3
+ import GuardianClient from '../guardian';
4
+ import { RelayerClient } from './relayerClient';
5
+ interface PersonalSignParams {
6
+ ethSigner: Signer;
7
+ rpcProvider: JsonRpcProvider;
8
+ params: any[];
9
+ zkEvmAddress: string;
10
+ guardianClient: GuardianClient;
11
+ relayerClient: RelayerClient;
12
+ flow: Flow;
13
+ }
14
+ export declare const personalSign: ({ params, ethSigner, zkEvmAddress, rpcProvider, guardianClient, relayerClient, flow, }: PersonalSignParams) => Promise<string>;
15
+ export {};
@@ -0,0 +1,3 @@
1
+ import { EIP6963ProviderDetail, EIP6963ProviderInfo } from '../types';
2
+ export declare const passportProviderInfo: EIP6963ProviderInfo;
3
+ export declare function announceProvider(detail: EIP6963ProviderDetail): void;
@@ -0,0 +1,60 @@
1
+ import { BytesLike, JsonRpcProvider } from 'ethers';
2
+ import { AuthManager } from '@imtbl/auth';
3
+ import { WalletConfiguration } from '../config';
4
+ import { FeeOption, RelayerTransaction, TypedDataPayload } from './types';
5
+ export type RelayerClientInput = {
6
+ config: WalletConfiguration;
7
+ rpcProvider: JsonRpcProvider;
8
+ authManager: AuthManager;
9
+ };
10
+ type EthSendTransactionRequest = {
11
+ method: 'eth_sendTransaction';
12
+ params: {
13
+ to: string;
14
+ data: BytesLike;
15
+ chainId: string;
16
+ }[];
17
+ };
18
+ type ImGetTransactionByHashRequest = {
19
+ method: 'im_getTransactionByHash';
20
+ params: string[];
21
+ };
22
+ type ImGetFeeOptionsRequest = {
23
+ method: 'im_getFeeOptions';
24
+ params: {
25
+ userAddress: string;
26
+ data: BytesLike;
27
+ chainId: string;
28
+ }[];
29
+ };
30
+ type ImSignRequest = {
31
+ method: 'im_sign';
32
+ params: {
33
+ chainId: string;
34
+ address: string;
35
+ message: string;
36
+ }[];
37
+ };
38
+ type ImSignTypedDataRequest = {
39
+ method: 'im_signTypedData';
40
+ params: {
41
+ chainId: string;
42
+ address: string;
43
+ eip712Payload: TypedDataPayload;
44
+ }[];
45
+ };
46
+ export type RelayerTransactionRequest = EthSendTransactionRequest | ImGetTransactionByHashRequest | ImGetFeeOptionsRequest | ImSignTypedDataRequest | ImSignRequest;
47
+ export declare class RelayerClient {
48
+ private readonly config;
49
+ private readonly rpcProvider;
50
+ private readonly authManager;
51
+ constructor({ config, rpcProvider, authManager }: RelayerClientInput);
52
+ private static getResponsePreview;
53
+ private postToRelayer;
54
+ ethSendTransaction(to: string, data: BytesLike): Promise<string>;
55
+ imGetTransactionByHash(hash: string): Promise<RelayerTransaction>;
56
+ imGetFeeOptions(userAddress: string, data: BytesLike): Promise<FeeOption[] | undefined>;
57
+ imSignTypedData(address: string, eip712Payload: TypedDataPayload): Promise<string>;
58
+ imSign(address: string, message: string): Promise<string>;
59
+ }
60
+ export {};
@@ -0,0 +1,6 @@
1
+ import { TransactionParams } from './transactionHelpers';
2
+ type EthSendDeployTransactionParams = TransactionParams & {
3
+ params: Array<any>;
4
+ };
5
+ export declare const sendDeployTransactionAndPersonalSign: ({ params, ethSigner, rpcProvider, relayerClient, guardianClient, zkEvmAddress, flow, }: EthSendDeployTransactionParams) => Promise<string>;
6
+ export {};
@@ -0,0 +1,6 @@
1
+ import { TransactionParams } from './transactionHelpers';
2
+ type EthSendTransactionParams = TransactionParams & {
3
+ params: Array<any>;
4
+ };
5
+ export declare const sendTransaction: ({ params, ethSigner, rpcProvider, relayerClient, guardianClient, zkEvmAddress, flow, nonceSpace, isBackgroundTransaction, }: EthSendTransactionParams) => Promise<string>;
6
+ export {};
@@ -0,0 +1 @@
1
+ export declare function errorBoundary<T extends (...args: any[]) => any>(fn: T, fallbackResult?: ReturnType<T>): (...args: Parameters<T>) => ReturnType<T>;
@@ -0,0 +1,15 @@
1
+ import { Environment } from '@imtbl/config';
2
+ export declare const setupClient: (environment: Environment) => void;
3
+ type CheckParams = {
4
+ clientId: string;
5
+ wallet?: string;
6
+ checkCount?: number;
7
+ sendCount?: number;
8
+ };
9
+ export type CheckResponse = {
10
+ contractAddress?: string;
11
+ functionName?: string;
12
+ delay?: number;
13
+ };
14
+ export declare function get(queries: CheckParams): Promise<CheckResponse | undefined>;
15
+ export {};
@@ -0,0 +1,2 @@
1
+ import { AccountsRequestedEvent } from '../../types';
2
+ export declare const trackSessionActivity: (args: AccountsRequestedEvent) => Promise<void>;
@@ -0,0 +1,6 @@
1
+ import { EjectionTransactionParams, EjectionTransactionResponse } from './transactionHelpers';
2
+ type EthSendTransactionEjectionParams = EjectionTransactionParams & {
3
+ params: Array<any>;
4
+ };
5
+ export declare const signEjectionTransaction: ({ params, ethSigner, zkEvmAddress, flow, }: EthSendTransactionEjectionParams) => Promise<EjectionTransactionResponse>;
6
+ export {};
@@ -0,0 +1,14 @@
1
+ import { Flow } from '@imtbl/metrics';
2
+ import { Signer, JsonRpcProvider } from 'ethers';
3
+ import GuardianClient from '../guardian';
4
+ import { RelayerClient } from './relayerClient';
5
+ export type SignTypedDataV4Params = {
6
+ ethSigner: Signer;
7
+ rpcProvider: JsonRpcProvider;
8
+ relayerClient: RelayerClient;
9
+ method: string;
10
+ params: Array<any>;
11
+ guardianClient: GuardianClient;
12
+ flow: Flow;
13
+ };
14
+ export declare const signTypedDataV4: ({ params, method, ethSigner, rpcProvider, relayerClient, guardianClient, flow, }: SignTypedDataV4Params) => Promise<string>;
@@ -0,0 +1,31 @@
1
+ import { Flow } from '@imtbl/metrics';
2
+ import { Signer, TransactionRequest, JsonRpcProvider, BigNumberish } from 'ethers';
3
+ import { RelayerClient } from './relayerClient';
4
+ import GuardianClient from '../guardian';
5
+ export type TransactionParams = {
6
+ ethSigner: Signer;
7
+ rpcProvider: JsonRpcProvider;
8
+ guardianClient: GuardianClient;
9
+ relayerClient: RelayerClient;
10
+ zkEvmAddress: string;
11
+ flow: Flow;
12
+ nonceSpace?: bigint;
13
+ isBackgroundTransaction?: boolean;
14
+ };
15
+ export type EjectionTransactionParams = Pick<TransactionParams, 'ethSigner' | 'zkEvmAddress' | 'flow'>;
16
+ export type EjectionTransactionResponse = {
17
+ to: string;
18
+ data: string;
19
+ chainId: string;
20
+ };
21
+ export declare const pollRelayerTransaction: (relayerClient: RelayerClient, relayerId: string, flow: Flow) => Promise<import("./types").RelayerTransaction>;
22
+ export declare const prepareAndSignTransaction: ({ transactionRequest, ethSigner, rpcProvider, guardianClient, relayerClient, zkEvmAddress, flow, nonceSpace, isBackgroundTransaction, }: TransactionParams & {
23
+ transactionRequest: TransactionRequest;
24
+ }) => Promise<{
25
+ signedTransactions: string;
26
+ relayerId: string;
27
+ nonce: BigNumberish;
28
+ }>;
29
+ export declare const prepareAndSignEjectionTransaction: ({ transactionRequest, ethSigner, zkEvmAddress, flow, }: EjectionTransactionParams & {
30
+ transactionRequest: TransactionRequest;
31
+ }) => Promise<EjectionTransactionResponse>;
@@ -0,0 +1,120 @@
1
+ import { BigNumberish } from 'ethers';
2
+ import { JsonRpcError } from './JsonRpcError';
3
+ export declare enum RelayerTransactionStatus {
4
+ PENDING = "PENDING",
5
+ SUBMITTED = "SUBMITTED",
6
+ SUCCESSFUL = "SUCCESSFUL",
7
+ REVERTED = "REVERTED",
8
+ FAILED = "FAILED",
9
+ CANCELLED = "CANCELLED"
10
+ }
11
+ export interface RelayerTransaction {
12
+ status: RelayerTransactionStatus;
13
+ chainId: string;
14
+ relayerId: string;
15
+ hash: string;
16
+ statusMessage?: string;
17
+ }
18
+ export interface FeeOption {
19
+ tokenPrice: string;
20
+ tokenSymbol: string;
21
+ tokenDecimals: number;
22
+ tokenAddress: string;
23
+ recipientAddress: string;
24
+ }
25
+ export interface MetaTransaction {
26
+ to: string;
27
+ value?: BigNumberish | null;
28
+ data?: string | null;
29
+ nonce?: BigNumberish;
30
+ gasLimit?: BigNumberish;
31
+ delegateCall?: boolean;
32
+ revertOnError?: boolean;
33
+ }
34
+ export interface MetaTransactionNormalised {
35
+ delegateCall: boolean;
36
+ revertOnError: boolean;
37
+ gasLimit: BigNumberish;
38
+ target: string;
39
+ value: BigNumberish;
40
+ data: string;
41
+ }
42
+ export interface TypedDataPayload {
43
+ types: {
44
+ EIP712Domain: Array<{
45
+ name: string;
46
+ type: string;
47
+ }>;
48
+ [key: string]: Array<{
49
+ name: string;
50
+ type: string;
51
+ }>;
52
+ };
53
+ domain: {
54
+ name?: string;
55
+ version?: string;
56
+ chainId?: number | string;
57
+ verifyingContract?: string;
58
+ salt?: string;
59
+ } | {
60
+ name?: string;
61
+ version?: string;
62
+ chainId?: number;
63
+ verifyingContract?: string;
64
+ salt?: string;
65
+ };
66
+ primaryType: string;
67
+ message: Record<string, any>;
68
+ }
69
+ export interface RequestArguments {
70
+ method: string;
71
+ params?: Array<any>;
72
+ }
73
+ export type JsonRpcRequestPayload = RequestArguments & {
74
+ jsonrpc?: string;
75
+ id?: string | number;
76
+ };
77
+ export interface JsonRpcRequestCallback {
78
+ (err: JsonRpcError | null, result?: JsonRpcResponsePayload | (JsonRpcResponsePayload | null)[] | null): void;
79
+ }
80
+ export interface JsonRpcResponsePayload {
81
+ result?: Array<any> | null;
82
+ error?: JsonRpcError | null;
83
+ jsonrpc?: string;
84
+ id?: string | number;
85
+ }
86
+ export type Provider = {
87
+ request: (request: RequestArguments) => Promise<any>;
88
+ on: (event: string, listener: (...args: any[]) => void) => void;
89
+ removeListener: (event: string, listener: (...args: any[]) => void) => void;
90
+ isPassport: boolean;
91
+ };
92
+ export declare enum ProviderEvent {
93
+ ACCOUNTS_CHANGED = "accountsChanged"
94
+ }
95
+ export type AccountsChangedEvent = Array<string>;
96
+ export interface ProviderEventMap extends Record<string, any> {
97
+ [ProviderEvent.ACCOUNTS_CHANGED]: [AccountsChangedEvent];
98
+ }
99
+ /**
100
+ * Event detail from the `eip6963:announceProvider` event.
101
+ */
102
+ export interface EIP6963ProviderDetail {
103
+ info: EIP6963ProviderInfo;
104
+ provider: Provider;
105
+ }
106
+ /**
107
+ * Metadata of the EIP-1193 Provider.
108
+ */
109
+ export interface EIP6963ProviderInfo {
110
+ icon: `data:image/${string}`;
111
+ name: string;
112
+ rdns: string;
113
+ uuid: string;
114
+ }
115
+ /**
116
+ * Event type to announce an EIP-1193 Provider.
117
+ */
118
+ export interface EIP6963AnnounceProviderEvent extends CustomEvent<EIP6963ProviderDetail> {
119
+ type: 'eip6963:announceProvider';
120
+ }
@@ -0,0 +1 @@
1
+ export * from './registerZkEvmUser';
@@ -0,0 +1,13 @@
1
+ import { MultiRollupApiClients } from '@imtbl/generated-clients';
2
+ import { Flow } from '@imtbl/metrics';
3
+ import { Signer, JsonRpcProvider } from 'ethers';
4
+ import { AuthManager } from '@imtbl/auth';
5
+ export type RegisterZkEvmUserInput = {
6
+ authManager: AuthManager;
7
+ ethSigner: Signer;
8
+ multiRollupApiClients: MultiRollupApiClients;
9
+ accessToken: string;
10
+ rpcProvider: JsonRpcProvider;
11
+ flow: Flow;
12
+ };
13
+ export declare function registerZkEvmUser({ authManager, ethSigner, multiRollupApiClients, accessToken, rpcProvider, flow, }: RegisterZkEvmUserInput): Promise<string>;
@@ -0,0 +1,33 @@
1
+ import { BigNumberish, Signer, JsonRpcProvider } from 'ethers';
2
+ import { MetaTransaction, MetaTransactionNormalised, TypedDataPayload } from './types';
3
+ export declare const getNormalisedTransactions: (txs: MetaTransaction[]) => MetaTransactionNormalised[];
4
+ export declare const digestOfTransactionsAndNonce: (nonce: BigNumberish, normalisedTransactions: MetaTransactionNormalised[]) => string;
5
+ export declare const encodedTransactions: (normalisedTransactions: MetaTransactionNormalised[]) => string;
6
+ /**
7
+ * This helper function is used to coerce the type <BigNumber | undefined> to BigNumber for the
8
+ * getNonce function above.
9
+ * @param {BigNumber} nonceSpace - An unsigned 256 bit value that can be used to encode a nonce into a distinct space.
10
+ * @returns {BigNumber} The passed in nonceSpace or instead initialises the nonce to 0.
11
+ */
12
+ export declare const coerceNonceSpace: (nonceSpace?: bigint) => bigint;
13
+ /**
14
+ * This helper function is used to encode the nonce into a 256 bit value where the space is encoded into
15
+ * the first 160 bits, and the nonce the remaining 96 bits.
16
+ * @param {BigNumber} nonceSpace - An unsigned 256 bit value that can be used to encode a nonce into a distinct space.
17
+ * @param nonce {BigNumber} nonce - Sequential number starting at 0, and incrementing in single steps e.g. 0,1,2,...
18
+ * @returns {BigNumber} The encoded value where the space is left shifted 96 bits, and the nonce is in the first 96 bits.
19
+ */
20
+ export declare const encodeNonce: (nonceSpace: bigint, nonce: bigint) => bigint;
21
+ /**
22
+ * When we retrieve a nonce for a smart contract wallet we can retrieve the nonce in a given 256 bit space.
23
+ * Nonces in each 256 bit space need to be sequential per wallet address. Nonces across 256 bit spaces per
24
+ * wallet address do not. This function overload can be used to invoke transactions in parallel per smart
25
+ * contract wallet if required.
26
+ */
27
+ export declare const getNonce: (rpcProvider: JsonRpcProvider, smartContractWalletAddress: string, nonceSpace?: bigint) => Promise<bigint>;
28
+ export declare const encodeMessageSubDigest: (chainId: bigint, walletAddress: string, digest: string) => string;
29
+ export declare const signMetaTransactions: (metaTransactions: MetaTransaction[], nonce: BigNumberish, chainId: bigint, walletAddress: string, signer: Signer) => Promise<string>;
30
+ export declare const packSignatures: (EOASignature: string, EOAAddress: string, relayerSignature: string) => string;
31
+ export declare const signAndPackTypedData: (typedData: TypedDataPayload, relayerSignature: string, chainId: bigint, walletAddress: string, signer: Signer) => Promise<string>;
32
+ export declare const signERC191Message: (chainId: bigint, payload: string, signer: Signer, walletAddress: string) => Promise<string>;
33
+ export declare const getEip155ChainId: (chainId: number) => string;