Skip to content

Commit c943535

Browse files
feat(auth): LIT-4211 - Migrate lit-auth-client providers and relayer module to auth package
1 parent 829efbd commit c943535

24 files changed

+86
-267
lines changed

packages/lit-auth-client/src/lib/providers/AppleProvider.ts renamed to packages/auth/src/lib/authenticators/AppleAuthenticator.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ import {
1212
OAuthProviderOptions,
1313
} from '@lit-protocol/types';
1414

15+
import { BaseAuthenticator } from './BaseAuthenticator';
1516
import {
1617
prepareLoginUrl,
1718
parseLoginParams,
1819
getStateParam,
1920
decode,
20-
} from '../utils';
21-
import { BaseProvider } from './BaseProvider';
21+
} from './utils';
2222

23-
export default class AppleProvider extends BaseProvider {
23+
export class AppleAuthenticator extends BaseAuthenticator {
2424
/**
2525
* The redirect URI that Lit's login server should send the user back to
2626
*/
@@ -142,7 +142,7 @@ export default class AppleProvider extends BaseProvider {
142142
* @returns {Promise<string>} - Auth method id
143143
*/
144144
public async getAuthMethodId(authMethod: AuthMethod): Promise<string> {
145-
return AppleProvider.authMethodId(authMethod);
145+
return AppleAuthenticator.authMethodId(authMethod);
146146
}
147147
public static async authMethodId(authMethod: AuthMethod): Promise<string> {
148148
const tokenPayload = jose.decodeJwt(authMethod.accessToken);

packages/lit-auth-client/src/lib/providers/BaseProvider.ts renamed to packages/auth/src/lib/authenticators/BaseAuthenticator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import {
2020
MintRequestBody,
2121
} from '@lit-protocol/types';
2222

23-
import { validateMintRequestBody } from '../validators';
23+
import { validateMintRequestBody } from './validators';
2424

25-
export abstract class BaseProvider {
25+
export abstract class BaseAuthenticator {
2626
/**
2727
* Relay server to subsidize minting of PKPs
2828
*/

packages/lit-auth-client/src/lib/providers/DiscordProvider.ts renamed to packages/auth/src/lib/authenticators/DiscordAuthenticator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ import {
1111
OAuthProviderOptions,
1212
} from '@lit-protocol/types';
1313

14-
import { BaseProvider } from './BaseProvider';
14+
import { BaseAuthenticator } from './BaseAuthenticator';
1515
import {
1616
prepareLoginUrl,
1717
parseLoginParams,
1818
getStateParam,
1919
decode,
2020
LIT_LOGIN_GATEWAY,
21-
} from '../utils';
21+
} from './utils';
2222

23-
export default class DiscordProvider extends BaseProvider {
23+
export class DiscordAuthenticator extends BaseAuthenticator {
2424
/**
2525
* The redirect URI that Lit's login server should send the user back to
2626
*/

packages/lit-auth-client/src/lib/providers/EthWalletProvider.ts renamed to packages/auth/src/lib/authenticators/EthWalletAuthenticator.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ import {
2020
EthWalletAuthenticateOptions,
2121
} from '@lit-protocol/types';
2222

23-
import { BaseProvider } from './BaseProvider';
23+
import { BaseAuthenticator } from './BaseAuthenticator';
2424

2525
interface DomainAndOrigin {
2626
domain?: string;
2727
origin?: string;
2828
}
2929

30-
export default class EthWalletProvider extends BaseProvider {
30+
export class EthWalletAuthenticator extends BaseAuthenticator {
3131
/**
3232
* The domain from which the signing request is made
3333
*/
@@ -40,7 +40,8 @@ export default class EthWalletProvider extends BaseProvider {
4040
constructor(options: EthWalletProviderOptions & BaseProviderOptions) {
4141
super(options);
4242

43-
const { domain, origin } = EthWalletProvider.getDomainAndOrigin(options);
43+
const { domain, origin } =
44+
EthWalletAuthenticator.getDomainAndOrigin(options);
4445
this.domain = domain;
4546
this.origin = origin;
4647
}
@@ -84,7 +85,7 @@ export default class EthWalletProvider extends BaseProvider {
8485
);
8586
}
8687

87-
return EthWalletProvider.authenticate({
88+
return EthWalletAuthenticator.authenticate({
8889
signer: options,
8990
address: options.address,
9091
chain: options.chain,
@@ -108,7 +109,7 @@ export default class EthWalletProvider extends BaseProvider {
108109
* @param {string} [options.origin] - Origin from which the signing request is made
109110
* @returns {Promise<AuthMethod>} - Auth method object containing the auth signature
110111
* @static
111-
* @memberof EthWalletProvider
112+
* @memberof EthWalletAuthenticator
112113
*
113114
* @example
114115
* ```typescript
@@ -169,7 +170,7 @@ export default class EthWalletProvider extends BaseProvider {
169170
expiration || new Date(Date.now() + 1000 * 60 * 60 * 24).toISOString();
170171

171172
const { domain: resolvedDomain, origin: resolvedOrigin } =
172-
EthWalletProvider.getDomainAndOrigin({ domain, origin });
173+
EthWalletAuthenticator.getDomainAndOrigin({ domain, origin });
173174

174175
// Prepare Sign in with Ethereum message
175176
const preparedMessage: Partial<SiweMessage> = {
@@ -217,7 +218,7 @@ export default class EthWalletProvider extends BaseProvider {
217218
* @returns {Promise<string>} - Auth method id
218219
*/
219220
public async getAuthMethodId(authMethod: AuthMethod): Promise<string> {
220-
return EthWalletProvider.authMethodId(authMethod);
221+
return EthWalletAuthenticator.authMethodId(authMethod);
221222
}
222223

223224
public static async authMethodId(authMethod: AuthMethod): Promise<string> {

packages/lit-auth-client/src/lib/providers/GoogleProvider.ts renamed to packages/auth/src/lib/authenticators/GoogleAuthenticator.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ import {
1212
OAuthProviderOptions,
1313
} from '@lit-protocol/types';
1414

15+
import { BaseAuthenticator } from './BaseAuthenticator';
1516
import {
1617
prepareLoginUrl,
1718
parseLoginParams,
1819
getStateParam,
1920
decode,
2021
LIT_LOGIN_GATEWAY,
21-
} from '../utils';
22-
import { BaseProvider } from './BaseProvider';
22+
} from './utils';
2323

24-
export default class GoogleProvider extends BaseProvider {
24+
export class GoogleAuthenticator extends BaseAuthenticator {
2525
/**
2626
* The redirect URI that Lit's login server should send the user back to
2727
*/
@@ -211,7 +211,7 @@ export default class GoogleProvider extends BaseProvider {
211211
* @returns {Promise<string>} - Auth method id
212212
*/
213213
public async getAuthMethodId(authMethod: AuthMethod): Promise<string> {
214-
return GoogleProvider.authMethodId(authMethod);
214+
return GoogleAuthenticator.authMethodId(authMethod);
215215
}
216216

217217
public static async authMethodId(authMethod: AuthMethod): Promise<string> {

packages/lit-auth-client/src/lib/providers/WebAuthnProvider.ts renamed to packages/auth/src/lib/authenticators/WebAuthnAuthenticator.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import {
1919
WebAuthnProviderOptions,
2020
} from '@lit-protocol/types';
2121

22-
import { getRPIdFromOrigin, parseAuthenticatorData } from '../utils';
23-
import { BaseProvider } from './BaseProvider';
22+
import { BaseAuthenticator } from './BaseAuthenticator';
23+
import { getRPIdFromOrigin, parseAuthenticatorData } from './utils';
2424

25-
export default class WebAuthnProvider extends BaseProvider {
25+
export class WebAuthnAuthenticator extends BaseAuthenticator {
2626
/**
2727
* Name of relying party. Defaults to "lit"
2828
*/
@@ -70,7 +70,7 @@ export default class WebAuthnProvider extends BaseProvider {
7070

7171
// Get auth method pub key
7272
const authMethodPubkey =
73-
WebAuthnProvider.getPublicKeyFromRegistration(attResp);
73+
WebAuthnAuthenticator.getPublicKeyFromRegistration(attResp);
7474

7575
// Format args for relay server
7676
const defaultArgs = {
@@ -178,7 +178,7 @@ export default class WebAuthnProvider extends BaseProvider {
178178
* @returns {Promise<string>} - Auth method id
179179
*/
180180
public async getAuthMethodId(authMethod: AuthMethod): Promise<string> {
181-
return WebAuthnProvider.authMethodId(authMethod, this.rpName);
181+
return WebAuthnAuthenticator.authMethodId(authMethod, this.rpName);
182182
}
183183

184184
public static async authMethodId(
Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,27 @@
1-
// AuthProviders live in this dir tree
1+
import { AppleAuthenticator } from './AppleAuthenticator';
2+
import { DiscordAuthenticator } from './DiscordAuthenticator';
3+
import { EthWalletAuthenticator } from './EthWalletAuthenticator';
4+
import { GoogleAuthenticator } from './GoogleAuthenticator';
5+
import { LitRelay } from '../relay';
6+
import { StytchAuthFactorOtpAuthenticator } from './stytch/StytchAuthFactorOtpAuthenticator';
7+
import { StytchOtpAuthenticator } from './stytch/StytchOtpAuthenticator';
8+
import {
9+
isSignInRedirect,
10+
getProviderFromUrl,
11+
getAuthIdByAuthMethod,
12+
} from './utils';
13+
import { WebAuthnAuthenticator } from './WebAuthnAuthenticator';
14+
15+
export {
16+
LitRelay,
17+
AppleAuthenticator,
18+
DiscordAuthenticator,
19+
EthWalletAuthenticator,
20+
GoogleAuthenticator,
21+
StytchAuthFactorOtpAuthenticator,
22+
StytchOtpAuthenticator,
23+
WebAuthnAuthenticator,
24+
isSignInRedirect,
25+
getProviderFromUrl,
26+
getAuthIdByAuthMethod,
27+
};

packages/lit-auth-client/src/lib/providers/StytchAuthFactorOtp.ts renamed to packages/auth/src/lib/authenticators/stytch/StytchAuthFactorOtpAuthenticator.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ import {
1212
StytchToken,
1313
} from '@lit-protocol/types';
1414

15-
import { BaseProvider } from './BaseProvider';
15+
import { BaseAuthenticator } from '../BaseAuthenticator';
1616
import {
1717
FactorParser,
1818
emailOtpAuthFactorParser,
1919
smsOtpAuthFactorParser,
2020
totpAuthFactorParser,
2121
whatsAppOtpAuthFactorParser,
22-
} from './StytchAuthFactors';
22+
} from './parsers';
2323

24-
export default class StytchAuthFactorOtpProvider<
24+
export class StytchAuthFactorOtpAuthenticator<
2525
T extends FactorParser
26-
> extends BaseProvider {
26+
> extends BaseAuthenticator {
2727
private _factor: T;
2828
private static _provider: string = 'https://stytch.com/session';
2929

@@ -64,13 +64,16 @@ export default class StytchAuthFactorOtpProvider<
6464
}
6565

6666
const parsedToken: StytchToken =
67-
StytchAuthFactorOtpProvider._parseJWT(accessToken);
68-
const factorParser = StytchAuthFactorOtpProvider._resolveAuthFactor(
67+
StytchAuthFactorOtpAuthenticator._parseJWT(accessToken);
68+
const factorParser = StytchAuthFactorOtpAuthenticator._resolveAuthFactor(
6969
this._factor
7070
);
7171

7272
try {
73-
factorParser.parser(parsedToken, StytchAuthFactorOtpProvider._provider);
73+
factorParser.parser(
74+
parsedToken,
75+
StytchAuthFactorOtpAuthenticator._provider
76+
);
7477
} catch (e) {
7578
reject(e);
7679
}
@@ -91,7 +94,7 @@ export default class StytchAuthFactorOtpProvider<
9194
* @returns {Promise<string>} - Auth method id
9295
*/
9396
public async getAuthMethodId(authMethod: AuthMethod): Promise<string> {
94-
return StytchAuthFactorOtpProvider.authMethodId(authMethod);
97+
return StytchAuthFactorOtpAuthenticator.authMethodId(authMethod);
9598
}
9699

97100
/**
@@ -107,7 +110,7 @@ export default class StytchAuthFactorOtpProvider<
107110
return new Promise<string>((resolve, reject) => {
108111
const accessToken = authMethod.accessToken;
109112
const parsedToken: StytchToken =
110-
StytchAuthFactorOtpProvider._parseJWT(accessToken);
113+
StytchAuthFactorOtpAuthenticator._parseJWT(accessToken);
111114
let factor: FactorParser = 'email';
112115
switch (authMethod.authMethodType) {
113116
case AUTH_METHOD_TYPE.StytchEmailFactorOtp:

packages/lit-auth-client/src/lib/providers/StytchOtpProvider.ts renamed to packages/auth/src/lib/authenticators/stytch/StytchOtpAuthenticator.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import {
99
StytchOtpProviderOptions,
1010
} from '@lit-protocol/types';
1111

12-
import { BaseProvider } from './BaseProvider';
12+
import { BaseAuthenticator } from '../BaseAuthenticator';
1313

14-
export class StytchOtpProvider extends BaseProvider {
14+
export class StytchOtpAuthenticator extends BaseAuthenticator {
1515
private _params: StytchOtpProviderOptions;
1616
private _provider: string = 'https://stytch.com/session';
1717

@@ -48,7 +48,8 @@ export class StytchOtpProvider extends BaseProvider {
4848
);
4949
}
5050

51-
const parsedToken: StytchToken = StytchOtpProvider._parseJWT(accessToken);
51+
const parsedToken: StytchToken =
52+
StytchOtpAuthenticator._parseJWT(accessToken);
5253
const audience = (parsedToken['aud'] as string[])[0];
5354
if (audience != this._params.appId) {
5455
reject(new Error('Parsed application id does not match parameters'));
@@ -92,11 +93,11 @@ export class StytchOtpProvider extends BaseProvider {
9293
* @returns {Promise<string>} - Auth method id
9394
*/
9495
public async getAuthMethodId(authMethod: AuthMethod): Promise<string> {
95-
return StytchOtpProvider.authMethodId(authMethod);
96+
return StytchOtpAuthenticator.authMethodId(authMethod);
9697
}
9798

9899
public static async authMethodId(authMethod: AuthMethod): Promise<string> {
99-
const tokenBody = StytchOtpProvider._parseJWT(authMethod.accessToken);
100+
const tokenBody = StytchOtpAuthenticator._parseJWT(authMethod.accessToken);
100101
const userId = tokenBody['sub'] as string;
101102
const orgId = (tokenBody['aud'] as string[])[0];
102103
const authMethodId = ethers.utils.keccak256(

0 commit comments

Comments
 (0)