UNPKG

@saberhq/sail

Version:

Account caching and batched loading for React-based Solana applications.

24 lines 647 B
import { Keypair } from "@solana/web3.js"; import { useMemo } from "react"; /** * Parses a Keypair from a JSON secret key. * @param valueStr The string representation of the JSON secret key. * @returns */ export const useKeypair = (valueStr) => { return useMemo(() => { if (typeof valueStr !== "string") { return valueStr; } if (!valueStr) { return null; } try { return Keypair.fromSecretKey(Uint8Array.from([...JSON.parse(valueStr)])); } catch (e) { return null; } }, [valueStr]); }; //# sourceMappingURL=useKeypair.js.map