Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kinode/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ pub async fn simulate_node(
routing: NodeRouting::Direct {
ip: "127.0.0.1".into(),
ports: std::collections::BTreeMap::from([("ws".to_string(), ws_port)]),
}
},
};

let decoded_keyfile = Keyfile {
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion kinode/src/register-ui/build/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<meta httpEquiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport"
content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1.00001, viewport-fit=cover" />
<script type="module" crossorigin src="/assets/index-Do8ILYvr.js"></script>
<script type="module" crossorigin src="/assets/index-2wTC9S_W.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-B00cPdAQ.css">
</head>

Expand Down
99 changes: 55 additions & 44 deletions kinode/src/register-ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
import { ethers } from "ethers";
import ConnectWallet from "./components/ConnectWallet";
import RegisterEthName from "./pages/RegisterEthName";
import RegisterOsName from "./pages/RegisterKnsName";
import RegisterKnsName from "./pages/RegisterKnsName";
import ClaimOsInvite from "./pages/ClaimKnsInvite";
import SetPassword from "./pages/SetPassword";
import Login from './pages/Login'
Expand Down Expand Up @@ -67,42 +67,47 @@ function App() {

const rpcUrl = useMemo(() => provider?.network?.chainId === ChainId.SEPOLIA ? import.meta.env.REACT_APP_SEPOLIA_RPC_URL : import.meta.env.REACT_APP_OPTIMISM_RPC_URL, [provider])

const [dotOs, setDotOs] = useState<DotOsRegistrar>(
DotOsRegistrar__factory.connect(
provider?.network?.chainId === ChainId.SEPOLIA ? DOT_OS_ADDRESSES[ChainId.SEPOLIA] : DOT_OS_ADDRESSES[ChainId.OPTIMISM],
new ethers.providers.JsonRpcProvider(rpcUrl))
);

const [kns, setKns] = useState<KNSRegistryResolver>(
KNSRegistryResolver__factory.connect(
provider?.network?.chainId === ChainId.SEPOLIA ? KNS_REGISTRY_ADDRESSES[ChainId.SEPOLIA] : KNS_REGISTRY_ADDRESSES[ChainId.OPTIMISM],
new ethers.providers.JsonRpcProvider(rpcUrl))
);

const [knsEnsEntry, setKnsEnsEntry] = useState<KNSEnsEntry>(
KNSEnsEntry__factory.connect(
provider?.network?.chainId === ChainId.SEPOLIA ? KNS_ENS_ENTRY_ADDRESSES[ChainId.SEPOLIA] : KNS_ENS_ENTRY_ADDRESSES[ChainId.MAINNET],
// set rpc url based on chain id
new ethers.providers.JsonRpcProvider(provider?.network?.chainId === ChainId.SEPOLIA ? import.meta.env.REACT_APP_SEPOLIA_RPC_URL : import.meta.env.REACT_APP_MAINNET_RPC_URL))
);

const [knsEnsExit, setKnsEnsExit] = useState<KNSEnsExit>(
KNSEnsExit__factory.connect(
provider?.network?.chainId === ChainId.SEPOLIA ? KNS_ENS_EXIT_ADDRESSES[ChainId.SEPOLIA] : KNS_ENS_EXIT_ADDRESSES[ChainId.OPTIMISM],
new ethers.providers.JsonRpcProvider(rpcUrl))
);

const [nameWrapper, setNameWrapper] = useState<NameWrapper>(
NameWrapper__factory.connect(
provider?.network?.chainId === ChainId.SEPOLIA ? NAMEWRAPPER_ADDRESSES[ChainId.SEPOLIA] : NAMEWRAPPER_ADDRESSES[ChainId.MAINNET],
new ethers.providers.JsonRpcProvider(rpcUrl))
);

const [ensRegistry, setEnsRegistry] = useState<ENSRegistry>(
ENSRegistry__factory.connect(
provider?.network?.chainId === ChainId.SEPOLIA ? ENS_REGISTRY_ADDRESSES[ChainId.SEPOLIA] : ENS_REGISTRY_ADDRESSES[ChainId.MAINNET],
new ethers.providers.JsonRpcProvider(rpcUrl))
);
const [dotOs, setDotOs] = useState<DotOsRegistrar>();
const [kns, setKns] = useState<KNSRegistryResolver>();
const [knsEnsEntry, setKnsEnsEntry] = useState<KNSEnsEntry>();
const [knsEnsExit, setKnsEnsExit] = useState<KNSEnsExit>();
const [nameWrapper, setNameWrapper] = useState<NameWrapper>();
const [ensRegistry, setEnsRegistry] = useState<ENSRegistry>();

useEffect(() => {
if (rpcUrl) {
setDotOs(DotOsRegistrar__factory.connect(
provider?.network?.chainId === ChainId.SEPOLIA ? DOT_OS_ADDRESSES[ChainId.SEPOLIA] : DOT_OS_ADDRESSES[ChainId.OPTIMISM],
new ethers.providers.JsonRpcProvider(rpcUrl)
))

setKns(KNSRegistryResolver__factory.connect(
provider?.network?.chainId === ChainId.SEPOLIA ? KNS_REGISTRY_ADDRESSES[ChainId.SEPOLIA] : KNS_REGISTRY_ADDRESSES[ChainId.OPTIMISM],
new ethers.providers.JsonRpcProvider(rpcUrl)
))

setKnsEnsEntry(KNSEnsEntry__factory.connect(
provider?.network?.chainId === ChainId.SEPOLIA ? KNS_ENS_ENTRY_ADDRESSES[ChainId.SEPOLIA] : KNS_ENS_ENTRY_ADDRESSES[ChainId.MAINNET],
new ethers.providers.JsonRpcProvider(provider?.network?.chainId === ChainId.SEPOLIA ? import.meta.env.REACT_APP_SEPOLIA_RPC_URL : import.meta.env.REACT_APP_MAINNET_RPC_URL)
))

setKnsEnsExit(KNSEnsExit__factory.connect(
provider?.network?.chainId === ChainId.SEPOLIA ? KNS_ENS_EXIT_ADDRESSES[ChainId.SEPOLIA] : KNS_ENS_EXIT_ADDRESSES[ChainId.OPTIMISM],
new ethers.providers.JsonRpcProvider(rpcUrl)
))

setNameWrapper(NameWrapper__factory.connect(
provider?.network?.chainId === ChainId.SEPOLIA ? NAMEWRAPPER_ADDRESSES[ChainId.SEPOLIA] : NAMEWRAPPER_ADDRESSES[ChainId.MAINNET],
new ethers.providers.JsonRpcProvider(rpcUrl)
))

setEnsRegistry(ENSRegistry__factory.connect(
provider?.network?.chainId === ChainId.SEPOLIA ? ENS_REGISTRY_ADDRESSES[ChainId.SEPOLIA] : ENS_REGISTRY_ADDRESSES[ChainId.MAINNET],
new ethers.providers.JsonRpcProvider(rpcUrl)
))
}

}, [rpcUrl, provider])

useEffect(() => setAppSizeOnLoad(
(window.performance.getEntriesByType('navigation') as any)[0].transferSize
Expand Down Expand Up @@ -136,9 +141,11 @@ function App() {
const nodeChainId = await currentChainResponse.json()
setNodeChainId(nodeChainId.toLowerCase())
console.log('Node Chain ID:', nodeChainId)
} else {
console.error('error processing chain response', currentChainResponse)
}
} catch {
console.log('error getting current chain')
} catch (e) {
console.error('error getting current chain', e)
}
})()
}, []) // eslint-disable-line react-hooks/exhaustive-deps
Expand Down Expand Up @@ -213,10 +220,14 @@ function App() {
reset, setReset,
pw, setPw,
knsName, setOsName,
dotOs, kns,
knsEnsEntryNetwork, knsEnsExitNetwork,
knsEnsEntry, knsEnsExit,
nameWrapper, ensRegistry,
dotOs: dotOs!,
kns: kns!,
knsEnsEntry: knsEnsEntry!,
knsEnsExit: knsEnsExit!,
nameWrapper: nameWrapper!,
ensRegistry: ensRegistry!,
knsEnsEntryNetwork,
knsEnsExitNetwork,
connectOpen, openConnect, closeConnect,
provider, appSizeOnLoad,
networkingKey, setNetworkingKey,
Expand All @@ -236,7 +247,7 @@ function App() {
: <KinodeHome {...props} />
} />
<Route path="/claim-invite" element={<ClaimOsInvite {...props} />} />
<Route path="/register-name" element={<RegisterOsName {...props} />} />
<Route path="/register-name" element={<RegisterKnsName {...props} />} />
<Route path="/register-eth-name" element={<RegisterEthName {...props} />} />
<Route path="/set-password" element={<SetPassword {...props} />} />
<Route path="/reset" element={<Reset {...props} />} />
Expand Down
4 changes: 2 additions & 2 deletions kinode/src/register-ui/src/components/EnterKnsName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type ClaimOsNameProps = {
setName: React.Dispatch<React.SetStateAction<string>>;
nameValidities: string[];
setNameValidities: React.Dispatch<React.SetStateAction<string[]>>;
dotOs: DotOsRegistrar;
dotOs?: DotOsRegistrar;
triggerNameCheck: boolean;
isReset?: boolean;
};
Expand Down Expand Up @@ -65,7 +65,7 @@ function EnterKnsName({
index = validities.indexOf(NAME_CLAIMED);
if (validities.length === 0 || index !== -1) {
try {
await dotOs.ownerOf(hash(normalized));
await dotOs?.ownerOf(hash(normalized));
if (index === -1) validities.push(NAME_CLAIMED);
} catch (e) {
if (index !== -1) validities.splice(index, 1);
Expand Down
25 changes: 8 additions & 17 deletions kinode/src/register-ui/src/components/KnsHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import classNames from "classnames";

const { useIsActivating, useChainId } = hooks;

type OsHeaderProps = {
type KinodeHeaderProps = {
header: ReactNode;
nameLogo?: boolean;
nodeChainId: string;
Expand All @@ -28,26 +28,21 @@ function KinodeHeader({
closeConnect,
nodeChainId,
hideConnect = false,
}: OsHeaderProps) {
}: KinodeHeaderProps) {
const { account, isActive } = useWeb3React();
const isActivating = useIsActivating();
const chainId = useChainId();

const [networkName, setNetworkName] = useState("");

useEffect(() => {
setNetworkName(getNetworkName((chainId || 1).toString()));
setNetworkName(getNetworkName(chainId?.toString()));
}, [chainId]);

const connectWallet = useCallback(async () => {
closeConnect();
await metaMask.activate().catch(() => { });

try {
setChain(nodeChainId);
} catch (error) {
console.error(error);
}
await metaMask.activate();
setChain(nodeChainId);
}, [closeConnect, nodeChainId]);

const changeToNodeChain = useCallback(async () => {
Expand All @@ -60,11 +55,7 @@ function KinodeHeader({
);
}

try {
setChain(nodeChainId);
} catch (error) {
console.error(error);
}
setChain(nodeChainId);
}
}, [chainId, nodeChainId]);

Expand Down Expand Up @@ -97,12 +88,12 @@ function KinodeHeader({
className="network-icon"
src={optimismLogo}
/>
) : null}
) : 'Not connected'}
text={nodeChainId === SEPOLIA_OPT_HEX
? `Your Kinode is currently pointed at Sepolia. To point at Optimism, boot without the "--testnet" flag.`
: nodeChainId === OPTIMISM_OPT_HEX
? `Your Kinode is currently pointed at Optimism. To point at Sepolia, boot with the "--testnet" flag.`
: ''}
: 'Your Kinode is not pointed at a chain.'}
/>
)}
<div className="flex flex-col gap-4 c">
Expand Down
15 changes: 10 additions & 5 deletions kinode/src/register-ui/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,17 @@ export interface PageProps {
}

export type NetworkingInfo = {
name: string,
networking_key: string,
ws_routing: [
ip_address: string,
port: number
],
allowed_routers: string[]
routing: {
Both: {
ip: string,
ports: {
ws: number
},
routers: string[]
}
},
}

export type UnencryptedIdentity = {
Expand Down
17 changes: 12 additions & 5 deletions kinode/src/register-ui/src/pages/ClaimKnsInvite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,15 @@ function ClaimOsInvite({

const {
networking_key,
ws_routing: [ip_address, port],
allowed_routers,
routing: {
Both: {
ip: ip_address,
ports: {
ws: port
},
routers
}
}
} = (await fetch("/generate-networking-info", { method: "POST" }).then(
(res) => res.json()
)) as NetworkingInfo;
Expand All @@ -80,7 +87,7 @@ function ClaimOsInvite({
setNetworkingKey(networking_key);
setIpAddress(ipAddress);
setPort(port);
setRouters(allowed_routers);
setRouters(routers);

if (nameValidities.length !== 0 || inviteValidity !== "") return;
if (!name || !invite) {
Expand All @@ -93,7 +100,7 @@ function ClaimOsInvite({
setLoaderMsg("...Building EIP-4337 User Operation");
setIsLoading(true);

console.log("BUILDING", networking_key, ipAddress, port, allowed_routers);
console.log("BUILDING", networking_key, ipAddress, port, routers);

try {
response = await fetch(process.env.REACT_APP_BUILD_USER_OP_POST!, {
Expand All @@ -105,7 +112,7 @@ function ClaimOsInvite({
networkingKey: networking_key,
wsIp: ipAddress,
wsPort: port,
routers: allowed_routers,
routers: routers,
direct: direct,
}),
});
Expand Down
13 changes: 10 additions & 3 deletions kinode/src/register-ui/src/pages/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,15 @@ function Login({
// Generate keys on server that are stored temporarily
const {
networking_key,
ws_routing: [ip_address, port],
allowed_routers,
routing: {
Both: {
ip: ip_address,
ports: {
ws: port
},
routers: allowed_routers
}
},
} = (await fetch("/generate-networking-info", {
method: "POST",
}).then((res) => res.json())) as NetworkingInfo;
Expand Down Expand Up @@ -140,7 +147,7 @@ function Login({

// Login or confirm new keys
const result = await fetch(
reset ? "/confirm-change-network-keys" : "login",
reset ? "/api/confirm-change-network-keys" : "login",
{
method: "POST",
headers: { "Content-Type": "application/json" },
Expand Down
11 changes: 9 additions & 2 deletions kinode/src/register-ui/src/pages/RegisterEthName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,15 @@ function RegisterEthName({

const {
networking_key,
ws_routing: [ip_address, port],
allowed_routers,
routing: {
Both: {
ip: ip_address,
ports: {
ws: port
},
routers: allowed_routers
}
}
} = (await fetch("/generate-networking-info", { method: "POST" }).then(
(res) => res.json()
)) as NetworkingInfo;
Expand Down
Loading