@saberhq/sail
Version:
Account caching and batched loading for React-based Solana applications.
28 lines • 806 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.useKeypair = void 0;
const web3_js_1 = require("@solana/web3.js");
const react_1 = require("react");
/**
* Parses a Keypair from a JSON secret key.
* @param valueStr The string representation of the JSON secret key.
* @returns
*/
const useKeypair = (valueStr) => {
return (0, react_1.useMemo)(() => {
if (typeof valueStr !== "string") {
return valueStr;
}
if (!valueStr) {
return null;
}
try {
return web3_js_1.Keypair.fromSecretKey(Uint8Array.from([...JSON.parse(valueStr)]));
}
catch (e) {
return null;
}
}, [valueStr]);
};
exports.useKeypair = useKeypair;
//# sourceMappingURL=useKeypair.js.map
;