@@ -5,21 +5,24 @@ import type {
55 Config ,
66 Environment ,
77} from '@dialectlabs/sdk' ;
8- import { EncryptionKeysProvider } from '@dialectlabs/sdk' ;
8+ import { EncryptionKeysProvider , IllegalArgumentError } from '@dialectlabs/sdk' ;
99import type { DialectSolanaWalletAdapter } from '../wallet-adapter/dialect-solana-wallet-adapter.interface' ;
1010import { DialectSolanaWalletAdapterEncryptionKeysProvider } from '../encryption/encryption-keys-provider' ;
1111import { SolanaEd25519AuthenticationFacadeFactory } from '../auth/ed25519/solana-ed25519-authentication-facade-factory' ;
1212import { DialectWalletAdapterSolanaEd25519TokenSigner } from '../auth/ed25519/solana-ed25519-token-signer' ;
1313import { SolanaTxAuthenticationFacadeFactory } from '../auth/tx/solana-tx-authentication-facade-factory' ;
1414import { DialectWalletAdapterSolanaTxTokenSigner } from '../auth/tx/solana-tx-token-signer' ;
15+ import { SolanaSignMessageV2AuthenticationFacadeFactory } from '../auth/sign-message-v2/solana-sign-message-v2-authentication-facade-factory' ;
1516import { DIALECT_BLOCKCHAIN_SDK_TYPE_SOLANA } from './constants' ;
1617
1718export interface SolanaConfigProps {
1819 wallet : DialectSolanaWalletAdapter ;
20+ authVersion ?: 1 | 2 ;
1921}
2022
2123export interface SolanaConfig extends SolanaConfigProps {
2224 wallet : DialectSolanaWalletAdapterWrapper ;
25+ authVersion : 1 | 2 ;
2326}
2427
2528export type SolanaNetwork = 'mainnet-beta' | 'devnet' | 'localnet' ;
@@ -63,6 +66,7 @@ Solana settings:
6366 walletAdapterEncryptionKeysProvider ,
6467 config . encryptionKeysStore ,
6568 ) ;
69+
6670 const authenticationFacadeFactory = wallet . canSignMessage ( )
6771 ? new SolanaEd25519AuthenticationFacadeFactory (
6872 new DialectWalletAdapterSolanaEd25519TokenSigner ( wallet ) ,
@@ -83,12 +87,37 @@ Solana settings:
8387 } ;
8488 }
8589
90+ createAuthenticationFacade ( solanaConfig : SolanaConfig , config : Config ) {
91+ if ( solanaConfig . authVersion === 1 ) {
92+ if ( solanaConfig . wallet . canSignMessage ( ) ) {
93+ return new SolanaEd25519AuthenticationFacadeFactory (
94+ new DialectWalletAdapterSolanaEd25519TokenSigner ( solanaConfig . wallet ) ,
95+ ) . get ( ) ;
96+ }
97+ if ( solanaConfig . wallet . canSignTransaction ( ) ) {
98+ return new SolanaTxAuthenticationFacadeFactory (
99+ new DialectWalletAdapterSolanaTxTokenSigner ( solanaConfig . wallet ) ,
100+ ) . get ( ) ;
101+ }
102+ }
103+ if ( solanaConfig . authVersion === 2 ) {
104+ if ( solanaConfig . wallet . canSignMessage ( ) ) {
105+ return new SolanaSignMessageV2AuthenticationFacadeFactory (
106+ new DialectWalletAdapterSolanaEd25519TokenSigner ( solanaConfig . wallet ) ,
107+ config . dialectCloud . v2Url ,
108+ ) . get ( ) ;
109+ }
110+ }
111+ throw new IllegalArgumentError ( 'Unsupported auth version' ) ;
112+ }
113+
86114 private initializeSolanaConfig ( ) : SolanaConfig {
87115 const wallet = new DialectSolanaWalletAdapterWrapper (
88116 this . solanaConfigProps . wallet ,
89117 ) ;
90118 return {
91119 wallet,
120+ authVersion : this . solanaConfigProps . authVersion ?? 2 ,
92121 } ;
93122 }
94123}
0 commit comments