UNPKG

@lifi/sdk

Version:

LI.FI Any-to-Any Cross-Chain-Swap SDK

67 lines 2.3 kB
import { ed25519 } from '@noble/curves/ed25519'; import { BaseSignerWalletAdapter, isVersionedTransaction, WalletConfigError, WalletNotConnectedError, WalletReadyState, } from '@solana/wallet-adapter-base'; import { Keypair } from '@solana/web3.js'; import bs58 from 'bs58'; export const KeypairWalletName = 'Keypair Wallet'; /** * This keypair wallet adapter is unsafe to use on the frontend and is only included to provide an easy way for applications to test * Wallet Adapter without using a third-party wallet. */ export class KeypairWalletAdapter extends BaseSignerWalletAdapter { name = KeypairWalletName; url = 'https://github.com/anza-xyz/wallet-adapter'; icon = ''; supportedTransactionVersions = new Set([ 'legacy', 0, ]); /** * Storing a keypair locally like this is not safe because any application using this adapter could retrieve the * secret key, and because the keypair will be lost any time the wallet is disconnected or the window is refreshed. */ _keypair; constructor(privateKey) { if (!privateKey) { throw new WalletConfigError(); } super(); this._keypair = Keypair.fromSecretKey(bs58.decode(privateKey)); } get connecting() { return false; } get publicKey() { return this._keypair?.publicKey || null; } get readyState() { return WalletReadyState.Loadable; } async connect(privateKey) { if (!privateKey) { throw new WalletConfigError(); } this._keypair = Keypair.fromSecretKey(bs58.decode(privateKey)); } async disconnect() { this._keypair = undefined; } async signTransaction(transaction) { if (!this._keypair) { throw new WalletNotConnectedError(); } if (isVersionedTransaction(transaction)) { transaction.sign([this._keypair]); } else { transaction.partialSign(this._keypair); } return transaction; } async signMessage(message) { if (!this._keypair) { throw new WalletNotConnectedError(); } return ed25519.sign(message, this._keypair.secretKey.slice(0, 32)); } } //# sourceMappingURL=KeypairWalletAdapter.js.map