import l from "tweetnacl";
import { useLocalStorageState as a } from "ahooks";
import { useEffect as s } from "react";
import { encodeKey as t, encrypt as d, decrypt as u } from "../../utils.js";
const r = l.box.keyPair();
function z() {
  const [c, i] = a("__encKey", {
    defaultValue: t(r.publicKey),
    deserializer: (e) => e,
    serializer: (e) => e
  }), [o, p] = a("__decKey", {
    defaultValue: t(r.secretKey),
    deserializer: (e) => e,
    serializer: (e) => e
  });
  return s(() => {
    localStorage.getItem("__encKey") || i(t(r.publicKey)), localStorage.getItem("__decKey") || p(t(r.secretKey));
  }, []), {
    encryptKey: c,
    decryptKey: o,
    decrypt: (e, y = c, n = o) => u(e, y, n),
    encrypt: (e, y = c) => d(e, y)
  };
}
export {
  z as default
};
