@@ -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,16 @@ export class SignIn extends BaseResource implements SignInResource {
444451 } ) ;
445452 } ;
446453
454+ public authenticateWithSolana = async ( params : SignInAuthenticateWithSolanaParams ) : Promise < SignInResource > => {
455+ const identifier = await web3 ( ) . getSolanaIdentifier ( params . walletName ) ;
456+ return this . authenticateWithWeb3 ( {
457+ identifier,
458+ generateSignature : p => web3 ( ) . generateSignatureWithSolana ( { ...p , walletName : params . walletName } ) ,
459+ strategy : 'web3_solana_signature' ,
460+ walletName : params . walletName ,
461+ } ) ;
462+ } ;
463+
447464 public authenticateWithPasskey = async ( params ?: AuthenticateWithPasskeyParams ) : Promise < SignInResource > => {
448465 const { flow } = params || { } ;
449466
@@ -961,7 +978,7 @@ class SignInFuture implements SignInFutureResource {
961978
962979 return runAsyncResourceTask ( this . #resource, async ( ) => {
963980 let identifier ;
964- let generateSignature ;
981+ let generateSignature : GenerateSignature ;
965982 switch ( provider ) {
966983 case 'metamask' :
967984 identifier = await web3 ( ) . getMetamaskIdentifier ( ) ;
@@ -979,6 +996,16 @@ class SignInFuture implements SignInFutureResource {
979996 identifier = await web3 ( ) . getOKXWalletIdentifier ( ) ;
980997 generateSignature = web3 ( ) . generateSignatureWithOKXWallet ;
981998 break ;
999+ case 'solana' :
1000+ if ( ! params . walletName ) {
1001+ throw new ClerkRuntimeError ( 'Wallet name is required for Solana authentication.' , {
1002+ code : 'web3_solana_wallet_name_required' ,
1003+ } ) ;
1004+ }
1005+ identifier = await web3 ( ) . getSolanaIdentifier ( params . walletName ) ;
1006+ generateSignature = p =>
1007+ web3 ( ) . generateSignatureWithSolana ( { ...p , walletName : params . walletName as string } ) ;
1008+ break ;
9821009 default :
9831010 throw new Error ( `Unsupported Web3 provider: ${ provider } ` ) ;
9841011 }
@@ -1004,7 +1031,12 @@ class SignInFuture implements SignInFutureResource {
10041031
10051032 let signature : string ;
10061033 try {
1007- signature = await generateSignature ( { identifier, nonce : message } ) ;
1034+ signature = await generateSignature ( {
1035+ identifier,
1036+ nonce : message ,
1037+ walletName : params ?. walletName ,
1038+ provider,
1039+ } ) ;
10081040 } catch ( err ) {
10091041 // There is a chance that as a user when you try to setup and use the Coinbase Wallet with an existing
10101042 // Passkey in order to authenticate, the initial generate signature request to be rejected. For this
@@ -1013,7 +1045,11 @@ class SignInFuture implements SignInFutureResource {
10131045 // error code 4001 means the user rejected the request
10141046 // Reference: https://docs.cdp.coinbase.com/wallet-sdk/docs/errors
10151047 if ( provider === 'coinbase_wallet' && err . code === 4001 ) {
1016- signature = await generateSignature ( { identifier, nonce : message } ) ;
1048+ signature = await generateSignature ( {
1049+ identifier,
1050+ nonce : message ,
1051+ provider,
1052+ } ) ;
10171053 } else {
10181054 throw err ;
10191055 }
0 commit comments