@@ -23,6 +23,7 @@ import type {
2323 EmailLinkConfig ,
2424 EmailLinkFactor ,
2525 EnterpriseSSOConfig ,
26+ GenerateSignature ,
2627 PassKeyConfig ,
2728 PasskeyFactor ,
2829 PhoneCodeConfig ,
@@ -32,6 +33,7 @@ import type {
3233 ResetPasswordEmailCodeFactorConfig ,
3334 ResetPasswordParams ,
3435 ResetPasswordPhoneCodeFactorConfig ,
36+ SignInAuthenticateWithSolanaParams ,
3537 SignInCreateParams ,
3638 SignInFirstFactor ,
3739 SignInFutureBackupCodeVerifyParams ,
@@ -202,6 +204,7 @@ export class SignIn extends BaseResource implements SignInResource {
202204 case 'web3_base_signature' :
203205 case 'web3_coinbase_wallet_signature' :
204206 case 'web3_okx_wallet_signature' :
207+ case 'web3_solana_signature' :
205208 config = { web3WalletId : params . web3WalletId } as Web3SignatureConfig ;
206209 break ;
207210 case 'reset_password_phone_code' :
@@ -363,13 +366,17 @@ export class SignIn extends BaseResource implements SignInResource {
363366 } ;
364367
365368 public authenticateWithWeb3 = async ( params : AuthenticateWithWeb3Params ) : Promise < SignInResource > => {
366- const { identifier, generateSignature, strategy = 'web3_metamask_signature' } = params || { } ;
369+ const { identifier, generateSignature, strategy = 'web3_metamask_signature' , walletName } = params || { } ;
367370 const provider = strategy . replace ( 'web3_' , '' ) . replace ( '_signature' , '' ) as Web3Provider ;
368371
369372 if ( ! ( typeof generateSignature === 'function' ) ) {
370373 clerkMissingOptionError ( 'generateSignature' ) ;
371374 }
372375
376+ if ( provider === 'solana' && ! walletName ) {
377+ clerkMissingOptionError ( 'walletName' ) ;
378+ }
379+
373380 await this . create ( { identifier } ) ;
374381
375382 const web3FirstFactor = this . supportedFirstFactors ?. find ( f => f . strategy === strategy ) as Web3SignatureFactor ;
@@ -387,7 +394,7 @@ export class SignIn extends BaseResource implements SignInResource {
387394
388395 let signature : string ;
389396 try {
390- signature = await generateSignature ( { identifier, nonce : message , provider } ) ;
397+ signature = await generateSignature ( { identifier, nonce : message , walletName , provider } ) ;
391398 } catch ( err ) {
392399 // There is a chance that as a user when you try to setup and use the Coinbase Wallet with an existing
393400 // Passkey in order to authenticate, the initial generate signature request to be rejected. For this
@@ -396,7 +403,7 @@ export class SignIn extends BaseResource implements SignInResource {
396403 // error code 4001 means the user rejected the request
397404 // Reference: https://docs.cdp.coinbase.com/wallet-sdk/docs/errors
398405 if ( provider === 'coinbase_wallet' && err . code === 4001 ) {
399- signature = await generateSignature ( { identifier, nonce : message , provider } ) ;
406+ signature = await generateSignature ( { identifier, nonce : message , provider, walletName } ) ;
400407 } else {
401408 throw err ;
402409 }
@@ -444,6 +451,31 @@ export class SignIn extends BaseResource implements SignInResource {
444451 } ) ;
445452 } ;
446453
454+ /**
455+ * Authenticates a user using a Solana Web3 wallet during sign-in.
456+ *
457+ * @param params - Configuration for Solana authentication
458+ * @param params.walletName - The name of the Solana wallet to use for authentication
459+ * @returns A promise that resolves to the updated SignIn resource
460+ * @throws {ClerkRuntimeError } If walletName is not provided or wallet connection fails
461+ *
462+ * @example
463+ * ```typescript
464+ * await signIn.authenticateWithSolana({ walletName: 'phantom' });
465+ * ```
466+ */
467+ public authenticateWithSolana = async ( {
468+ walletName,
469+ } : SignInAuthenticateWithSolanaParams ) : Promise < SignInResource > => {
470+ const identifier = await web3 ( ) . getSolanaIdentifier ( walletName ) ;
471+ return this . authenticateWithWeb3 ( {
472+ identifier,
473+ generateSignature : p => web3 ( ) . generateSignatureWithSolana ( { ...p , walletName : walletName } ) ,
474+ strategy : 'web3_solana_signature' ,
475+ walletName : walletName ,
476+ } ) ;
477+ } ;
478+
447479 public authenticateWithPasskey = async ( params ?: AuthenticateWithPasskeyParams ) : Promise < SignInResource > => {
448480 const { flow } = params || { } ;
449481
@@ -961,7 +993,7 @@ class SignInFuture implements SignInFutureResource {
961993
962994 return runAsyncResourceTask ( this . #resource, async ( ) => {
963995 let identifier ;
964- let generateSignature ;
996+ let generateSignature : GenerateSignature ;
965997 switch ( provider ) {
966998 case 'metamask' :
967999 identifier = await web3 ( ) . getMetamaskIdentifier ( ) ;
@@ -979,6 +1011,16 @@ class SignInFuture implements SignInFutureResource {
9791011 identifier = await web3 ( ) . getOKXWalletIdentifier ( ) ;
9801012 generateSignature = web3 ( ) . generateSignatureWithOKXWallet ;
9811013 break ;
1014+ case 'solana' :
1015+ if ( ! params . walletName ) {
1016+ throw new ClerkRuntimeError ( 'Wallet name is required for Solana authentication.' , {
1017+ code : 'web3_solana_wallet_name_required' ,
1018+ } ) ;
1019+ }
1020+ identifier = await web3 ( ) . getSolanaIdentifier ( params . walletName ) ;
1021+ generateSignature = p =>
1022+ web3 ( ) . generateSignatureWithSolana ( { ...p , walletName : params . walletName as string } ) ;
1023+ break ;
9821024 default :
9831025 throw new Error ( `Unsupported Web3 provider: ${ provider } ` ) ;
9841026 }
@@ -1004,7 +1046,12 @@ class SignInFuture implements SignInFutureResource {
10041046
10051047 let signature : string ;
10061048 try {
1007- signature = await generateSignature ( { identifier, nonce : message } ) ;
1049+ signature = await generateSignature ( {
1050+ identifier,
1051+ nonce : message ,
1052+ walletName : params ?. walletName ,
1053+ provider,
1054+ } ) ;
10081055 } catch ( err ) {
10091056 // There is a chance that as a user when you try to setup and use the Coinbase Wallet with an existing
10101057 // Passkey in order to authenticate, the initial generate signature request to be rejected. For this
@@ -1013,7 +1060,11 @@ class SignInFuture implements SignInFutureResource {
10131060 // error code 4001 means the user rejected the request
10141061 // Reference: https://docs.cdp.coinbase.com/wallet-sdk/docs/errors
10151062 if ( provider === 'coinbase_wallet' && err . code === 4001 ) {
1016- signature = await generateSignature ( { identifier, nonce : message } ) ;
1063+ signature = await generateSignature ( {
1064+ identifier,
1065+ nonce : message ,
1066+ provider,
1067+ } ) ;
10171068 } else {
10181069 throw err ;
10191070 }
0 commit comments