-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jsr を使うために esbuild を使う, secp256k1 で自動パスワード
- Loading branch information
1 parent
c0d9fbe
commit bd2f2b6
Showing
8 changed files
with
284 additions
and
36 deletions.
There are no files selected for viewing
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,71 @@ | ||
import { | ||
Dispatch, | ||
StateUpdater, | ||
} from "https://esm.sh/[email protected]/hooks?pin=v135"; | ||
import { h } from "https://esm.sh/[email protected]?pin=v135"; | ||
import { encodeBase64Url } from "jsr:@std/encoding/base64url"; | ||
|
||
export const App = (props: { | ||
readonly state: number; | ||
readonly privateKey: Uint8Array | null; | ||
readonly setState: Dispatch<StateUpdater<number>>; | ||
readonly signUp: () => void; | ||
readonly copyPassword: () => void; | ||
}) => { | ||
return ( | ||
<div | ||
style={{ | ||
display: "grid", | ||
gap: 16, | ||
}} | ||
> | ||
<h1>definy</h1> | ||
<button | ||
type="button" | ||
onClick={() => { | ||
props.setState((prev) => prev + 1); | ||
}} | ||
> | ||
count: {props.state} | ||
</button> | ||
<button type="button" onClick={props.signUp}> | ||
Sign Up | ||
</button> | ||
|
||
{props.privateKey === null ? <div></div> : ( | ||
<dialog | ||
open | ||
style={{ | ||
width: "80%", | ||
boxShadow: "0px 20px 36px 0px rgba(0, 0, 0, 0.6)", | ||
}} | ||
> | ||
<form | ||
style={{ | ||
display: "grid", | ||
}} | ||
> | ||
<label> | ||
Username | ||
<input type="text" required /> | ||
</label> | ||
<label> | ||
Password (auto created. If you lose this password, you will not be | ||
able to log in.) | ||
<input | ||
value={encodeBase64Url(props.privateKey)} | ||
readOnly={true} | ||
type="password" | ||
autoComplete="new-password" | ||
/> | ||
<button type="button" onClick={props.copyPassword}> | ||
copy password | ||
</button> | ||
</label> | ||
<button type="submit">sign up!</button> | ||
</form> | ||
</dialog> | ||
)} | ||
</div> | ||
); | ||
}; |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import { App } from "./main.tsx"; | ||
import { App } from "./app.tsx"; | ||
import { h, hydrate, JSX } from "https://esm.sh/[email protected]?pin=v135"; | ||
import { useState } from "https://esm.sh/[email protected]/hooks?pin=v135"; | ||
import { utils } from "jsr:@noble/secp256k1"; | ||
import { encodeBase64Url } from "jsr:@std/encoding/base64url"; | ||
|
||
const root = document.getElementById("root"); | ||
if (root === null) { | ||
|
@@ -9,7 +11,24 @@ if (root === null) { | |
|
||
const AppWithState = (): JSX.Element => { | ||
const [state, setState] = useState(0); | ||
return <App state={state} setState={setState} />; | ||
const [privateKey, setPrivateKey] = useState<Uint8Array | null>(null); | ||
|
||
return ( | ||
<App | ||
state={state} | ||
privateKey={privateKey} | ||
setState={setState} | ||
signUp={() => { | ||
setPrivateKey(utils.randomPrivateKey()); | ||
}} | ||
copyPassword={() => { | ||
if (privateKey === null) { | ||
return; | ||
} | ||
navigator.clipboard.writeText(encodeBase64Url(privateKey)); | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
hydrate(<AppWithState />, root); |
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
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
Oops, something went wrong.