@imtbl/passport 2.8.1-alpha.0 → 2.9.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,24 @@
1
+ import { AbstractSigner, Signer } from 'ethers';
2
+ import { MagicTeeApiClients } from '@imtbl/generated-clients';
3
+ import AuthManager from '../authManager';
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
+ }
@@ -3,6 +3,16 @@ import { MockedRequest, RequestHandler } from 'msw';
3
3
  export declare const relayerId = "0x745";
4
4
  export declare const transactionHash = "0x867";
5
5
  export declare const mswHandlers: {
6
+ magicTEE: {
7
+ createWallet: {
8
+ success: import("msw").RestHandler<MockedRequest<import("msw").DefaultBodyType>>;
9
+ internalServerError: import("msw").RestHandler<MockedRequest<import("msw").DefaultBodyType>>;
10
+ };
11
+ personalSign: {
12
+ success: import("msw").RestHandler<MockedRequest<import("msw").DefaultBodyType>>;
13
+ internalServerError: import("msw").RestHandler<MockedRequest<import("msw").DefaultBodyType>>;
14
+ };
15
+ };
6
16
  counterfactualAddress: {
7
17
  success: import("msw").RestHandler<MockedRequest<import("msw").DefaultBodyType>>;
8
18
  internalServerError: import("msw").RestHandler<MockedRequest<import("msw").DefaultBodyType>>;
@@ -2,16 +2,16 @@ import { AnyToken, IMXClient, NftTransferDetails, TokenAmount, UnsignedExchangeT
2
2
  import { IMXProvider } from '@imtbl/x-provider';
3
3
  import { imx, ImxApiClients } from '@imtbl/generated-clients';
4
4
  import { TransactionResponse } from 'ethers';
5
- import TypedEventEmitter from '../utils/typedEventEmitter';
6
5
  import AuthManager from '../authManager';
7
6
  import GuardianClient from '../guardian';
8
7
  import { PassportEventMap } from '../types';
9
- import MagicAdapter from '../magic/magicAdapter';
8
+ import MagicTEESigner from '../magic/magicTEESigner';
9
+ import TypedEventEmitter from '../utils/typedEventEmitter';
10
10
  export interface PassportImxProviderOptions {
11
11
  authManager: AuthManager;
12
12
  immutableXClient: IMXClient;
13
13
  passportEventEmitter: TypedEventEmitter<PassportEventMap>;
14
- magicAdapter: MagicAdapter;
14
+ magicTEESigner: MagicTEESigner;
15
15
  imxApiClients: ImxApiClients;
16
16
  guardianClient: GuardianClient;
17
17
  }
@@ -21,16 +21,16 @@ export declare class PassportImxProvider implements IMXProvider {
21
21
  private readonly immutableXClient;
22
22
  protected readonly guardianClient: GuardianClient;
23
23
  protected readonly imxApiClients: ImxApiClients;
24
- protected magicAdapter: MagicAdapter;
24
+ protected magicTEESigner: MagicTEESigner;
25
25
  /**
26
26
  * This property is set during initialisation and stores the signers in a promise.
27
27
  * This property is not meant to be accessed directly, but through the
28
28
  * `#getSigners` method.
29
29
  * @see #getSigners
30
30
  */
31
- private signers;
31
+ private starkSigner;
32
32
  private signerInitialisationError;
33
- constructor({ authManager, immutableXClient, passportEventEmitter, magicAdapter, imxApiClients, guardianClient, }: PassportImxProviderOptions);
33
+ constructor({ authManager, immutableXClient, passportEventEmitter, magicTEESigner, imxApiClients, guardianClient, }: PassportImxProviderOptions);
34
34
  private handleLogout;
35
35
  transfer(request: UnsignedTransferRequest): Promise<imx.CreateTransferResponseV1>;
36
36
  registerOffchain(): Promise<imx.RegisterUserResponse>;
@@ -2,14 +2,14 @@ import { IMXClient } from '@imtbl/x-client';
2
2
  import { IMXProvider } from '@imtbl/x-provider';
3
3
  import { ImxApiClients } from '@imtbl/generated-clients';
4
4
  import AuthManager from '../authManager';
5
- import MagicAdapter from '../magic/magicAdapter';
6
5
  import { PassportEventMap } from '../types';
7
- import TypedEventEmitter from '../utils/typedEventEmitter';
8
6
  import GuardianClient from '../guardian';
7
+ import MagicTEESigner from '../magic/magicTEESigner';
8
+ import TypedEventEmitter from '../utils/typedEventEmitter';
9
9
  export type PassportImxProviderFactoryInput = {
10
10
  authManager: AuthManager;
11
11
  immutableXClient: IMXClient;
12
- magicAdapter: MagicAdapter;
12
+ magicTEESigner: MagicTEESigner;
13
13
  passportEventEmitter: TypedEventEmitter<PassportEventMap>;
14
14
  imxApiClients: ImxApiClients;
15
15
  guardianClient: GuardianClient;
@@ -17,11 +17,11 @@ export type PassportImxProviderFactoryInput = {
17
17
  export declare class PassportImxProviderFactory {
18
18
  private readonly authManager;
19
19
  private readonly immutableXClient;
20
- private readonly magicAdapter;
20
+ private readonly magicTEESigner;
21
21
  private readonly passportEventEmitter;
22
22
  readonly imxApiClients: ImxApiClients;
23
23
  private readonly guardianClient;
24
- constructor({ authManager, immutableXClient, magicAdapter, passportEventEmitter, imxApiClients, guardianClient, }: PassportImxProviderFactoryInput);
24
+ constructor({ authManager, immutableXClient, magicTEESigner, passportEventEmitter, imxApiClients, guardianClient, }: PassportImxProviderFactoryInput);
25
25
  getProvider(): Promise<IMXProvider>;
26
26
  getProviderSilent(): Promise<IMXProvider | null>;
27
27
  private createProviderInstance;
@@ -1,5 +1,5 @@
1
1
  import { Environment, ModuleConfiguration } from '@imtbl/config';
2
- import { EthSigner, IMXClient, StarkSigner } from '@imtbl/x-client';
2
+ import { IMXClient } from '@imtbl/x-client';
3
3
  import { ImxApiClients } from '@imtbl/generated-clients';
4
4
  import { Flow } from '@imtbl/metrics';
5
5
  /**
@@ -30,18 +30,22 @@ export type UserProfile = {
30
30
  nickname?: string;
31
31
  sub: string;
32
32
  };
33
+ export declare enum RollupType {
34
+ IMX = "imx",
35
+ ZKEVM = "zkEvm"
36
+ }
33
37
  export type User = {
34
38
  idToken?: string;
35
39
  accessToken: string;
36
40
  refreshToken?: string;
37
41
  profile: UserProfile;
38
42
  expired?: boolean;
39
- imx?: {
43
+ [RollupType.IMX]?: {
40
44
  ethAddress: string;
41
45
  starkAddress: string;
42
46
  userAdminAddress: string;
43
47
  };
44
- zkEvm?: {
48
+ [RollupType.ZKEVM]?: {
45
49
  ethAddress: string;
46
50
  userAdminAddress: string;
47
51
  };
@@ -107,8 +111,8 @@ export interface PassportModuleConfiguration extends ModuleConfiguration<Passpor
107
111
  type WithRequired<T, K extends keyof T> = T & {
108
112
  [P in K]-?: T[P];
109
113
  };
110
- export type UserImx = WithRequired<User, 'imx'>;
111
- export type UserZkEvm = WithRequired<User, 'zkEvm'>;
114
+ export type UserImx = WithRequired<User, RollupType.IMX>;
115
+ export type UserZkEvm = WithRequired<User, RollupType.ZKEVM>;
112
116
  export declare const isUserZkEvm: (user: User) => user is UserZkEvm;
113
117
  export declare const isUserImx: (user: User) => user is UserImx;
114
118
  export type DeviceTokenResponse = {
@@ -135,10 +139,6 @@ export type PKCEData = {
135
139
  state: string;
136
140
  verifier: string;
137
141
  };
138
- export type IMXSigners = {
139
- starkSigner: StarkSigner;
140
- ethSigner: EthSigner;
141
- };
142
142
  export type LinkWalletParams = {
143
143
  type: string;
144
144
  walletAddress: string;
@@ -1,23 +1,24 @@
1
1
  import { MultiRollupApiClients } from '@imtbl/generated-clients';
2
+ import { Signer } from 'ethers';
2
3
  import { Provider, RequestArguments } from './types';
3
4
  import AuthManager from '../authManager';
4
- import MagicAdapter from '../magic/magicAdapter';
5
5
  import TypedEventEmitter from '../utils/typedEventEmitter';
6
6
  import { PassportConfiguration } from '../config';
7
- import { PassportEventMap } from '../types';
7
+ import { PassportEventMap, User } from '../types';
8
8
  import GuardianClient from '../guardian';
9
9
  export type ZkEvmProviderInput = {
10
10
  authManager: AuthManager;
11
- magicAdapter: MagicAdapter;
12
11
  config: PassportConfiguration;
13
12
  multiRollupApiClients: MultiRollupApiClients;
14
13
  passportEventEmitter: TypedEventEmitter<PassportEventMap>;
15
14
  guardianClient: GuardianClient;
15
+ ethSigner: Signer;
16
+ user: User | null;
16
17
  };
17
18
  export declare class ZkEvmProvider implements Provider {
18
19
  #private;
19
20
  readonly isPassport: boolean;
20
- constructor({ authManager, magicAdapter, config, multiRollupApiClients, passportEventEmitter, guardianClient, }: ZkEvmProviderInput);
21
+ constructor({ authManager, config, multiRollupApiClients, passportEventEmitter, guardianClient, ethSigner, user, }: ZkEvmProviderInput);
21
22
  request(request: RequestArguments): Promise<any>;
22
23
  on(event: string, listener: (...args: any[]) => void): void;
23
24
  removeListener(event: string, listener: (...args: any[]) => void): void;
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@imtbl/passport",
3
3
  "description": "Passport module for Immutable SDK",
4
- "version": "2.8.1-alpha.0",
4
+ "version": "2.9.0-alpha.0",
5
5
  "author": "Immutable",
6
6
  "bugs": "https://github.com/immutable/ts-immutable-sdk/issues",
7
7
  "dependencies": {
8
8
  "@0xsequence/abi": "^2.0.25",
9
9
  "@0xsequence/core": "^2.0.25",
10
- "@imtbl/config": "2.8.1-alpha.0",
11
- "@imtbl/generated-clients": "2.8.1-alpha.0",
12
- "@imtbl/metrics": "2.8.1-alpha.0",
13
- "@imtbl/toolkit": "2.8.1-alpha.0",
14
- "@imtbl/x-client": "2.8.1-alpha.0",
15
- "@imtbl/x-provider": "2.8.1-alpha.0",
10
+ "@imtbl/config": "2.9.0-alpha.0",
11
+ "@imtbl/generated-clients": "2.9.0-alpha.0",
12
+ "@imtbl/metrics": "2.9.0-alpha.0",
13
+ "@imtbl/toolkit": "2.9.0-alpha.0",
14
+ "@imtbl/x-client": "2.9.0-alpha.0",
15
+ "@imtbl/x-provider": "2.9.0-alpha.0",
16
16
  "@magic-ext/oidc": "12.0.5",
17
17
  "@magic-sdk/provider": "^29.0.5",
18
18
  "@metamask/detect-provider": "^2.0.0",
@@ -1,12 +0,0 @@
1
- import { Eip1193Provider } from 'ethers';
2
- import { PassportConfiguration } from '../config';
3
- import { MagicProviderProxyFactory } from './magicProviderProxyFactory';
4
- export default class MagicAdapter {
5
- private readonly config;
6
- private readonly magicProviderProxyFactory;
7
- private readonly magicClient?;
8
- constructor(config: PassportConfiguration, magicProviderProxyFactory: MagicProviderProxyFactory);
9
- private getMagicClient;
10
- login(idToken: string): Promise<Eip1193Provider>;
11
- logout(): Promise<void>;
12
- }
@@ -1,15 +0,0 @@
1
- import { Eip1193Provider } from 'ethers';
2
- import AuthManager from '../authManager';
3
- import { PassportConfiguration } from '../config';
4
- import { MagicClient } from './types';
5
- /**
6
- * Factory class for creating a Magic provider that automatically handles re-authentication.
7
- * This proxy wraps the Magic RPC provider to intercept certain RPC methods (`personal_sign`, `eth_accounts`)
8
- * and ensures the user is properly authenticated before executing them.
9
- */
10
- export declare class MagicProviderProxyFactory {
11
- private authManager;
12
- private config;
13
- constructor(authManager: AuthManager, config: PassportConfiguration);
14
- createProxy(magicClient: MagicClient): Eip1193Provider;
15
- }
@@ -1 +0,0 @@
1
- export {};