import { Keypair, PublicKey, Transaction, VersionedTransaction, } from '@solana/web3.js'; import { Convergence } from '..'; interface Wallet { signTransaction(tx: Transaction): Promise; signAllTransactions(txs: Transaction[]): Promise; publicKey: PublicKey; } export class CvgWallet implements Wallet { payer: Keypair; convergence: Convergence; publicKey: PublicKey; constructor(convergence: Convergence) { this.convergence = convergence; this.payer = convergence.rpc().getDefaultFeePayer() as Keypair; this.publicKey = convergence.identity().publicKey; } signTransaction = ( tx: T ): Promise => { if (tx instanceof VersionedTransaction) { throw new Error('Versioned transactions are not supported yet'); } return this.convergence.identity().signTransaction(tx) as Promise; }; signAllTransactions = ( txs: T[] ): Promise => { if (txs.find((tx) => tx instanceof VersionedTransaction) !== undefined) { throw new Error('Versioned transactions are not supported yet'); } return this.convergence .identity() .signAllTransactions(txs as Transaction[]) as Promise; }; } export class NoopWallet { public readonly publicKey: PublicKey; constructor(publicKey: PublicKey) { this.publicKey = publicKey; } // eslint-disable-next-line @typescript-eslint/no-unused-vars signTransaction(tx: Transaction): Promise { throw new Error('This Method is not expected to be called.'); } // eslint-disable-next-line @typescript-eslint/no-unused-vars signAllTransactions(txs: Transaction[]): Promise { throw new Error('This Method is not expected to be called.'); } }