-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
717ec21
commit 1b67510
Showing
4 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// pages/lp/utils.tsx | ||
|
||
import React, { useEffect, useRef, useState } from "react"; | ||
import { useRouter } from "next/router"; | ||
import styles from "../../../styles/Home.module.css"; | ||
import { testnetConstants } from "../../constants/configConstants"; | ||
import Layout from "../../components/layout"; | ||
import { VStack, Text, Spinner, Center, Box, HStack, Input, Button } from "@chakra-ui/react"; | ||
import { innerToBech32Address, bech32ToInner } from "../../utils/math/bech32"; | ||
|
||
export default function Utils() { | ||
const [innerAddress, setInnerAddress] = useState(""); | ||
const [bech32Address, setBech32Address] = useState(""); | ||
const [innerToBech32Output, setInnerToBech32Output] = useState(""); | ||
const [bech32ToInnerOutput, setBech32ToInnerOutput] = useState(""); | ||
|
||
const handleInnerToBech32 = () => { | ||
const bech32 = innerToBech32Address(innerAddress, "plpid"); | ||
setInnerToBech32Output(bech32); | ||
}; | ||
|
||
const handleBech32ToInner = () => { | ||
const inner = bech32ToInner(bech32Address); | ||
setBech32ToInnerOutput(inner); | ||
}; | ||
|
||
return ( | ||
<Layout pageTitle="Utils"> | ||
<Center height="100vh"> | ||
<VStack spacing={4}> | ||
<HStack spacing={2}> | ||
<Input | ||
placeholder="Enter B64 encoded Inner String" | ||
value={innerAddress} | ||
onChange={(e) => setInnerAddress(e.target.value)} | ||
width={"40em"} | ||
/> | ||
<Button | ||
colorScheme="purple" | ||
onClick={handleInnerToBech32} | ||
width={"20em"} | ||
> | ||
Convert to Bech32 | ||
</Button> | ||
</HStack> | ||
{innerToBech32Output && <Text>Bech32: {innerToBech32Output}</Text>} | ||
<VStack paddingBottom={"5em"}/> | ||
<HStack spacing={2}> | ||
<Input | ||
placeholder="Enter Bech32 Address" | ||
value={bech32Address} | ||
onChange={(e) => setBech32Address(e.target.value)} | ||
width={"40em"} | ||
/> | ||
<Button | ||
colorScheme="purple" | ||
onClick={handleBech32ToInner} | ||
width={"20em"} | ||
> | ||
Convert to B64 Inner | ||
</Button> | ||
</HStack> | ||
{bech32ToInnerOutput && <Text>Inner: {bech32ToInnerOutput}</Text>} | ||
</VStack> | ||
</Center> | ||
</Layout> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { bech32m } from "bech32"; | ||
import { uint8ArrayToBase64, base64ToUint8Array } from "./base64"; | ||
|
||
export const innerToBech32Address = (inner: string, prefix: string): string => { | ||
return bech32m.encode(prefix, bech32m.toWords(base64ToUint8Array(inner))); | ||
}; | ||
|
||
export const bech32ToInner = (addr: string): string => { | ||
const decodeAddress = bech32m.decode( | ||
addr, | ||
); | ||
return uint8ArrayToBase64( | ||
new Uint8Array(bech32m.fromWords(decodeAddress.words)) | ||
); | ||
}; |