UNPKG

@lifi/sdk

Version:

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

63 lines 2.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.KeypairWalletAdapter = exports.KeypairWalletName = void 0; const ed25519_1 = require("@noble/curves/ed25519"); const wallet_adapter_base_1 = require("@solana/wallet-adapter-base"); const web3_js_1 = require("@solana/web3.js"); const bs58_1 = require("bs58"); exports.KeypairWalletName = 'Keypair Wallet'; class KeypairWalletAdapter extends wallet_adapter_base_1.BaseSignerWalletAdapter { name = exports.KeypairWalletName; url = 'https://github.com/anza-xyz/wallet-adapter'; icon = ''; supportedTransactionVersions = new Set([ 'legacy', 0, ]); _keypair; constructor(privateKey) { if (!privateKey) { throw new wallet_adapter_base_1.WalletConfigError(); } super(); this._keypair = web3_js_1.Keypair.fromSecretKey(bs58_1.default.decode(privateKey)); } get connecting() { return false; } get publicKey() { return this._keypair?.publicKey || null; } get readyState() { return wallet_adapter_base_1.WalletReadyState.Loadable; } async connect(privateKey) { if (!privateKey) { throw new wallet_adapter_base_1.WalletConfigError(); } this._keypair = web3_js_1.Keypair.fromSecretKey(bs58_1.default.decode(privateKey)); } async disconnect() { this._keypair = undefined; } async signTransaction(transaction) { if (!this._keypair) { throw new wallet_adapter_base_1.WalletNotConnectedError(); } if ((0, wallet_adapter_base_1.isVersionedTransaction)(transaction)) { transaction.sign([this._keypair]); } else { transaction.partialSign(this._keypair); } return transaction; } async signMessage(message) { if (!this._keypair) { throw new wallet_adapter_base_1.WalletNotConnectedError(); } return ed25519_1.ed25519.sign(message, this._keypair.secretKey.slice(0, 32)); } } exports.KeypairWalletAdapter = KeypairWalletAdapter; //# sourceMappingURL=KeypairWalletAdapter.js.map