import { BaseSignerWalletAdapter , WalletAccountError , WalletDisconnectionError , WalletNotConnectedError , WalletNotReadyError , WalletPublicKeyError , WalletReadyState , WalletSignTransactionError , scopePollingDetectionStrategy , WalletName , Adapter , } from '@solana/wallet-adapter-base' ; import { PublicKey , Transaction } from '@solana/web3.js' ; interface BitKeepWallet { isBitKeep ? : boolean ; connect ( ) : Promise < void > ; disconnect ( ) : Promise < void > ; getAccount ( ) : Promise < string > ; signTransaction ( transaction ) : Promise < Transaction > ; signAllTransactions ( transactions ) : Promise < Transaction [ ] > ; } interface BitKeepWindow extends Window { bitkeep ? : { solana ? : BitKeepWallet ; } ; } declare const window ; export interface BitKeepWalletAdapterConfig { } export const BitKeepWalletName = 'BitKeep' as WalletName ; export class BitKeepWalletAdapter extends BaseSignerWalletAdapter { name = BitKeepWalletName ; url = 'https://bitkeep.com' ; icon = 'data:image/svg+xml;base64,PHN2ZyBmaWxsPSJub25lIiBoZWlnaHQ9IjEwMCIgdmlld0JveD0iMCAwIDEwMCAxMDAiIHdpZHRoPSIxMDAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGcgZmlsbD0iIzQ5NWJmZiI+PHBhdGggZD0ibTYyLjI4NTcgODcuOTY0NC0zNi44MTI5LTIxLjI2MzhjLTEuMjkzMi0uNzQ3Ni0yLjA4ODktMi4xMjctMi4wODg5LTMuNjIwOXYtNDIuNTc5NGMwLS42NDQyLS42OTctMS4wNDY5LTEuMjU1LS43MjQybC03LjUzMjUgNC4zNTVjLTIuODQ1IDEuNjQ1NC00LjU5NjQgNC42ODEzLTQuNTk2NCA3Ljk2NjF2MzUuODA3OWMwIDMuMjg2IDEuNzUxNCA2LjMyMTkgNC41OTY0IDcuOTY2MWwzMC45NTA0IDE3Ljg5MjljMi44NDg4IDEuNjQ3OSA2LjM2MTMgMS42NDc5IDkuMjExMyAwbDcuNTI3Ni00LjM1MjVjLjU1NzktLjMyMDIuNTU3OS0xLjEyNDUgMC0xLjQ0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2OC0uNzUwMDUtMi43MzA0LTEuMTU3NzEtNC4xNzY0LTEuMjI1NDUtLjIzNzctLjAxMTA5LS40MzYuMTgxMDQtLjQzNi40MTg3NXYxMy4xMjQwOWMwIC4yOTkzLjE1ODkuNTc1MS40MTc2LjcyNDJsMjQuMjY4OSAxNC4wMjMxYzEuMjkzMi43NDc2IDIuMDg4OCAyLjEyNyAyLjA4ODggMy42MjF2MjYuMTU1OGMwIDEuNDkzOS0uNzk2OCAyLjg3MzMtMi4wODg4IDMuNjIwOWwtMTYuNzMxNSA5LjY3MzFjLS41NTY3LjMyMjctLjU1NjcgMS4xMjY5IDAgMS40NDg0bDExLjI4OSA2LjUxNzdjLjUxODUuMjk5MyAxLjE1NjUuMjk5MyAxLjY3MzggMGwxNC42NDUxLTguNDY2MWMyLjg0MzgtMS42NDQyIDQuNTk2NC00LjY4MDIgNC41OTY0LTcuOTY2MXYtMzUuODA5MmMwLTMuMjg1OS0xLjc1MTQtNi4zMjE5LTQuNTk2NC03Ljk2NjF6Ii8+PC9nPjwvc3ZnPg==' ; private _connecting : boolean ; private _wallet : BitKeepWallet | null ; private _publicKey : PublicKey | null ; private _readyState : WalletReadyState = typeof window === 'undefined' || typeof document === 'undefined' ? WalletReadyState . Unsupported : WalletReadyState . NotDetected ; constructor ( config = { } ) { super ( ) ; this . _connecting = false ; this . _wallet = null ; this . _publicKey = null ; if ( this . _readyState !== WalletReadyState . Unsupported ) { scopePollingDetectionStrategy ( ( ) => { if ( window . bitkeep ?. solana ?. isBitKeep ) { this . _readyState = WalletReadyState . Installed ; this . emit ( 'readyStateChange' , this . _readyState ) ; return true ; } return false ; } ) ; } } get publicKey ( ) : PublicKey | null { return this . _publicKey ; } get connecting ( ) : boolean { return this . _connecting ; } get readyState ( ) : WalletReadyState { return this . _readyState ; } async connect ( ) { try { if ( this . connected || this . connecting ) return ; if ( this . _readyState !== WalletReadyState . Installed ) throw new WalletNotReadyError ( ) ; this . _connecting = true ; const wallet = window ! . bitkeep ! . solana ! ; let account ; try { account = await wallet . getAccount ( ) ; } catch ( error ) { throw new WalletAccountError ( error ?. message , error ) ; } let publicKey ; try { publicKey = new PublicKey ( account ) ; } catch ( error ) { throw new WalletPublicKeyError ( error ?. message , error ) ; } this . _wallet = wallet ; this . _publicKey = publicKey ; this . emit ( 'connect' , publicKey ) ; } catch ( error ) { this . emit ( 'error' , error ) ; throw error ; } finally { this . _connecting = false ; } } async disconnect ( ) { const wallet = this . _wallet ; if ( wallet ) { this . _wallet = null ; this . _publicKey = null ; try { await wallet . disconnect ( ) ; } catch ( error ) { this . emit ( 'error' , new WalletDisconnectionError ( error ?. message , error ) ) ; } } this . emit ( 'disconnect' ) ; } async signTransaction ( transaction ) { try { const wallet = this . _wallet ; if ( ! wallet ) throw new WalletNotConnectedError ( ) ; try { return ( await wallet . signTransaction ( transaction ) ) || transaction ; } catch ( error ) { throw new WalletSignTransactionError ( error ?. message , error ) ; } } catch ( error ) { this . emit ( 'error' , error ) ; throw error ; } } async signAllTransactions ( transactions ) { try { const wallet = this . _wallet ; if ( ! wallet ) throw new WalletNotConnectedError ( ) ; try { return ( await wallet . signAllTransactions ( transactions ) ) || transactions ; } catch ( error ) { throw new WalletSignTransactionError ( error ?. message , error ) ; } } catch ( error ) { this . emit ( 'error' , error ) ; throw error ; } } }