-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: blind xpub support for text input
- Loading branch information
Showing
5 changed files
with
113 additions
and
57 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
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
55 changes: 0 additions & 55 deletions
55
apps/coordinator/src/components/Wallet/TextExtendedPublicKeyImporter.jsx
This file was deleted.
Oops, something went wrong.
108 changes: 108 additions & 0 deletions
108
apps/coordinator/src/components/Wallet/TextExtendedPublicKeyImporter.tsx
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,108 @@ | ||
import React, { useEffect, useState } from "react"; | ||
|
||
// Components | ||
import { | ||
TextField, | ||
Box, | ||
Button, | ||
Grid, | ||
Alert, | ||
AlertTitle, | ||
Typography, | ||
} from "@mui/material"; | ||
import { Network, validateExtendedPublicKey } from "@caravan/bitcoin"; | ||
import { getBlindedXpub } from "@caravan/bip32"; | ||
import Copyable from "../Copyable"; | ||
|
||
const TextExtendedPublicKeyImporter = ({ | ||
validateAndSetExtendedPublicKey, | ||
network, | ||
}: { | ||
validateAndSetExtendedPublicKey: ( | ||
arg: string, | ||
arg1: (e: string) => void, | ||
) => void; | ||
network: Network; | ||
}) => { | ||
const [error, setError] = useState(""); | ||
const [xpub, setXpub] = useState(""); | ||
const [original, setOriginal] = useState(""); | ||
const [blindedPath, setBlindedPath] = useState(""); | ||
|
||
const handleSubmit = () => { | ||
validateAndSetExtendedPublicKey(xpub, setError); | ||
}; | ||
|
||
const handleBlind = () => { | ||
setOriginal(xpub); | ||
const blinded = getBlindedXpub(xpub); | ||
setXpub(blinded.xpub); | ||
setBlindedPath(blinded.bip32Path); | ||
}; | ||
|
||
useEffect(() => { | ||
if (xpub) { | ||
const error = validateExtendedPublicKey(xpub, network); | ||
setError(error); | ||
} | ||
}, [xpub]); | ||
|
||
return ( | ||
<Box mt={2}> | ||
<TextField | ||
fullWidth | ||
name="publicKey" | ||
label="Extended Public Key" | ||
value={xpub} | ||
variant="standard" | ||
onChange={(e) => setXpub(e.target.value)} | ||
error={error !== ""} | ||
helperText={error} | ||
multiline | ||
disabled={Boolean(original && blindedPath)} | ||
/> | ||
<Grid container style={{ marginTop: "12px" }} spacing={2}> | ||
<Grid item> | ||
<Button onClick={handleSubmit} variant="contained" color="primary"> | ||
Enter | ||
</Button> | ||
</Grid> | ||
<Grid item> | ||
<Button | ||
variant="outlined" | ||
color="info" | ||
disabled={!(!error && xpub)} | ||
onClick={handleBlind} | ||
> | ||
Blind | ||
</Button> | ||
</Grid> | ||
</Grid> | ||
{blindedPath && original && ( | ||
<Box my={4}> | ||
<Alert variant="outlined" severity="warning"> | ||
<AlertTitle> | ||
<h3 style={{ marginTop: "0px" }}> | ||
Blinded Info (IMPORTANT: Save this info) | ||
</h3> | ||
</AlertTitle> | ||
<Typography my={1}> | ||
<strong> | ||
Without the full bip32 path, your funds will be irrecoverable | ||
</strong> | ||
. This notice will dissapear once you hit "Enter". | ||
Check failure on line 93 in apps/coordinator/src/components/Wallet/TextExtendedPublicKeyImporter.tsx GitHub Actions / ci (20.x)
|
||
</Typography> | ||
<Typography variant="h6">Blinded Path:</Typography> | ||
<Copyable showIcon text={blindedPath} /> | ||
<Typography variant="h6"> Source Xpub:</Typography> | ||
<Copyable showIcon text={original} /> | ||
<Typography variant="h6">Blinded Xpub:</Typography> | ||
<Copyable showIcon text={xpub} /> | ||
</Alert> | ||
</Box> | ||
)} | ||
</Box> | ||
); | ||
}; | ||
|
||
export default TextExtendedPublicKeyImporter; |