Skip to content

Commit

Permalink
Skip private key if user is not logged in
Browse files Browse the repository at this point in the history
  • Loading branch information
chmac committed Aug 11, 2024
1 parent 6e9802b commit e77ce2e
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { getPublicKey } from "nostr-tools";
import Swal from "sweetalert2";
import { TRUSTED_VALIDATION_PUBKEYS } from "./constants";
import { getProfileFromEvent } from "./nostr/utils";
import { getPrivateKey, getRelays } from "./nostr";
import { _initRelays } from "./nostr/relays";
import { getPublicKey } from "nostr-tools";
import { hasPrivateKey } from "./nostr/keys";
import { getMetadataEvent } from "./nostr/subscribe";
import { getProfileFromEvent } from "./nostr/utils";

export const confirmYesNo = async (text: string) => {
const result = await Swal.fire({
Expand Down Expand Up @@ -77,17 +77,21 @@ export async function logStateToConsole() {
const relays = await getRelays();
const relayLine = relays.join(", ");

const privateKey = await getPrivateKey();
const publicKey = getPublicKey(privateKey);
const metadataEvent = await getMetadataEvent(publicKey);
const hasPrivateKeyResult = await hasPrivateKey();
let myProfileLine = "";
if (!metadataEvent) myProfileLine = `No profile: ${publicKey}`;
else {
const profile = getProfileFromEvent({ event: metadataEvent });
const line = `${profile.name} ${
profile.trustrootsUsername
} ${publicKey.substring(0, 10)}…`;
myProfileLine = line;
if (hasPrivateKeyResult) {
const privateKey = await getPrivateKey();
const publicKey = getPublicKey(privateKey);
const metadataEvent = await getMetadataEvent(publicKey);
if (!metadataEvent) {
myProfileLine = `No profile: ${publicKey}`;
} else {
const profile = getProfileFromEvent({ event: metadataEvent });
const line = `${profile.name} ${
profile.trustrootsUsername
} ${publicKey.substring(0, 10)}…`;
myProfileLine = line;
}
}
console.debug(`
# TRUSTED VALIDATION PUBKEYS
Expand Down

0 comments on commit e77ce2e

Please sign in to comment.