Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/lit 1862 js sdk add a abstract getauthmethodid public static function #254

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 2 additions & 22 deletions packages/contracts-sdk/src/lib/contracts-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BigNumberish, BytesLike, ethers } from 'ethers';
import { hexToDec, decToHex } from './hex2dec';
import bs58 from 'bs58';
import { isBrowser, isNode } from '@lit-protocol/misc';
import { DiscordProvider, EthWalletProvider, GoogleProvider, WebAuthnProvider } from '@lit-protocol/lit-auth-client';
import { LitAuthClient } from '@lit-protocol/lit-auth-client';

let CID: any;
try {
Expand Down Expand Up @@ -540,27 +540,7 @@ https://developer.litprotocol.com/v3/sdk/wallets/auth-methods/#auth-method-scope
return scope;
});

let authId;

switch (authMethod.authMethodType) {
case AuthMethodType.EthWallet:
authId = await EthWalletProvider.authMethodId(authMethod);
break;
case AuthMethodType.Discord:
authId = await DiscordProvider.authMethodId(authMethod);
break;
case AuthMethodType.WebAuthn:
authId = await WebAuthnProvider.authMethodId(authMethod);
break;
case AuthMethodType.GoogleJwt:
authId = await GoogleProvider.authMethodId(authMethod);
break;
case AuthMethodType.StytchOtp:
authId = await GoogleProvider.authMethodId(authMethod);
break;
default:
throw new Error(`Unsupported auth method type: ${authMethod.authMethodType}`);
}
const authId = await LitAuthClient.getAuthIdByAuthMethod(authMethod);

// -- go
const mintCost = await this.pkpNftContract.read.mintCost();
Expand Down
36 changes: 35 additions & 1 deletion packages/lit-auth-client/src/lib/lit-auth-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import {
StytchOtpProviderOptions,
ProviderOptions,
WebAuthnProviderOptions,
AuthMethod,
} from '@lit-protocol/types';
import { ProviderType } from '@lit-protocol/constants';
import { AuthMethodType, ProviderType } from '@lit-protocol/constants';
import { LitNodeClient } from '@lit-protocol/lit-node-client';
import { LitRelay } from './relay';
import { BaseProvider } from './providers/BaseProvider';
Expand Down Expand Up @@ -188,4 +189,37 @@ export class LitAuthClient {
getProvider(type: ProviderType): BaseProvider | undefined {
return this.providers.get(type);
}


/**
* Retrieves the authentication ID based on the provided authentication method.
*
* @param {AuthMethod} authMethod - The authentication method
* @returns {Promise<string>} - The authentication ID
*/
public static async getAuthIdByAuthMethod(authMethod: AuthMethod): Promise<string> {
let authId;

switch (authMethod.authMethodType) {
case AuthMethodType.EthWallet:
authId = await EthWalletProvider.authMethodId(authMethod);
break;
case AuthMethodType.Discord:
authId = await DiscordProvider.authMethodId(authMethod);
break;
case AuthMethodType.WebAuthn:
authId = await WebAuthnProvider.authMethodId(authMethod);
break;
case AuthMethodType.GoogleJwt:
authId = await GoogleProvider.authMethodId(authMethod);
break;
case AuthMethodType.StytchOtp:
authId = await GoogleProvider.authMethodId(authMethod);
break;
default:
throw new Error(`Unsupported auth method type: ${authMethod.authMethodType}`);
}

return authId;
}
}
Loading