From 43db7d9fdaf9877325aae02cdad9b7bf3adc01e9 Mon Sep 17 00:00:00 2001
From: polwex <polwex@sortug.com>
Date: Wed, 16 Jul 2025 16:54:11 +0700
Subject: XOR encryption working!!! fuck yeah!!!

---
 components/login/ShipCredsForm.tsx | 68 +++++++++++++++++++++++++++-----------
 1 file changed, 49 insertions(+), 19 deletions(-)

(limited to 'components/login/ShipCredsForm.tsx')

diff --git a/components/login/ShipCredsForm.tsx b/components/login/ShipCredsForm.tsx
index eebeeab..e4c872e 100644
--- a/components/login/ShipCredsForm.tsx
+++ b/components/login/ShipCredsForm.tsx
@@ -1,5 +1,4 @@
 "use client";
-import "core-js/actual/typed-array";
 import { ColorScheme, lightColors } from "@/constants";
 import {
   StyleSheet,
@@ -13,38 +12,32 @@ import { useState } from "react";
 import {
   createFancyPasskey,
   createPasskey,
+  getPasskeyFromUser,
   pkDecrypt,
+  pkDecryptXOR,
   pkEncrypt,
+  pkEncryptXOR,
 } from "@/lib/passkey";
 import toast from "react-hot-toast";
 import { makeWalletFromP } from "@/lib/urbit/wallet";
-import { hex2buf } from "@/lib/utils/bit";
+import { hex2buf, hex2bytes } from "@/lib/utils/bit";
 
 export function ShipForm() {
   const colors = lightColors;
   const styles = getStyles(colors);
   const [patp, setPatp] = useState("~mirtyl-wacdec");
   const [ticket, setTicket] = useState("~posseg-winnub-fogluc-dirmes");
+  const [ticketBytes, setTb] = useState<Uint8Array>();
+  const [ticketHash, setTh] = useState("");
   const [encryptedTicket, setenc] = useState("");
   const [isLoading, setIsLoading] = useState(false);
   async function onSubmit() {
     const wallet = await makeWalletFromP(patp, ticket);
     console.log("seed", wallet.ownership.seed);
     const privkey = wallet.ownership.keys.private;
-    const clean = privkey.replace(/^0x/i, "");
-    const byteLength = clean.length / 2;
-    toast(`bytes: ${byteLength}`);
-    const bufer = hex2buf(privkey);
-    toast(`buffer size: ${bufer.byteLength}`);
-    console.log(Uint8Array);
-    const ba = Uint8Array.fromHex(clean);
-    toast(`uintarray byte length: ${ba.byteLength}`);
-    console.log({
-      bufl: bufer.length,
-      bufbl: bufer.byteLength,
-      ul: ba.length,
-      ubl: ba.byteLength,
-    });
+    setTh(privkey);
+    const ba = hex2bytes(privkey);
+    setTb(ba);
   }
   async function makeFPk() {
     console.log("running", { patp, ticket });
@@ -58,17 +51,33 @@ export function ShipForm() {
     if ("error" in passkey) return toast.error(passkey.error);
     console.log({ passkey });
   }
+  async function checkPk() {
+    const passkey = await getPasskeyFromUser();
+    if ("error" in passkey) return toast.error(passkey.error);
+  }
   async function enc() {
-    const done = await pkEncrypt(ticket);
-    console.log({ encryptedTicket });
+    if (!ticketBytes) return toast("gotta build the wallet first");
+    const done = await pkEncryptXOR(ticketBytes);
+    console.log({ done });
     setenc(done);
     toast(done);
   }
   async function dec() {
-    const decryptedTicket = await pkDecrypt(encryptedTicket);
+    const decryptedTicket = await pkDecryptXOR(encryptedTicket);
     console.log({ decryptedTicket });
     toast(decryptedTicket);
   }
+  // async function enc() {
+  //   const done = await pkEncrypt(ticket);
+  //   console.log({ done});
+  //   setenc(done);
+  //   toast(done);
+  // }
+  // async function dec() {
+  //   const decryptedTicket = await pkDecrypt(encryptedTicket);
+  //   console.log({ decryptedTicket });
+  //   toast(decryptedTicket);
+  // }
   return (
     <View style={styles.bottomSection}>
       <TextInput
@@ -90,6 +99,18 @@ export function ShipForm() {
         autoCorrect={false}
         secureTextEntry
       />
+      <View>
+        <Text>Private Key</Text>
+        <View style={styles.surprise}>
+          <Text>{ticketHash}</Text>
+        </View>
+      </View>
+      <View>
+        <Text>Encrypted Private Key</Text>
+        <View style={styles.surprise}>
+          <Text>{encryptedTicket}</Text>
+        </View>
+      </View>
 
       <PrimaryButton
         label="Log in"
@@ -97,6 +118,12 @@ export function ShipForm() {
         style={{ marginTop: 0 }}
         isLoading={isLoading}
       />
+      <PrimaryButton
+        label="Chec Passkey"
+        onPress={checkPk}
+        style={{ marginTop: 0 }}
+        isLoading={isLoading}
+      />
       <PrimaryButton
         label="Make Passkey"
         onPress={makePk}
@@ -168,4 +195,7 @@ export const getStyles = (colors: ColorScheme) =>
       color: colors.text,
       fontSize: 16,
     },
+    surprise: {
+      backgroundColor: colors.card,
+    },
   });
-- 
cgit v1.2.3

