Skip to content

Commit

Permalink
feat: blind xpub support for text input
Browse files Browse the repository at this point in the history
  • Loading branch information
bucko13 committed Sep 6, 2024
1 parent c9b2fa7 commit e53e788
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 57 deletions.
1 change: 1 addition & 0 deletions apps/coordinator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"not op_mini all"
],
"dependencies": {
"@caravan/bip32": "*",
"@caravan/bitcoin": "*",
"@caravan/clients": "*",
"@caravan/descriptors": "^0.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React from "react";
import PropTypes from "prop-types";
import Dropzone from "react-dropzone";
import { Buffer } from "buffer/";
import { Buffer } from "buffer";
import { Box, Button, FormHelperText, Grid, TextField } from "@mui/material";
import { CloudUpload as UploadIcon } from "@mui/icons-material";
import { PSBT_MAGIC_HEX } from "@caravan/bitcoin";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ class ExtendedPublicKeyImporter extends React.Component {
<MenuItem value={TEXT}>Enter as text</MenuItem>
</TextField>
</FormControl>
<FormControl>{this.renderImportByMethod()}</FormControl>
<FormControl style={{ width: "100%" }}>
{this.renderImportByMethod()}
</FormControl>
</div>
);
};
Expand Down

This file was deleted.

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

View workflow job for this annotation

GitHub Actions / ci (20.x)

`"` can be escaped with `&quot;`, `&ldquo;`, `&#34;`, `&rdquo;`

Check failure on line 93 in apps/coordinator/src/components/Wallet/TextExtendedPublicKeyImporter.tsx

View workflow job for this annotation

GitHub Actions / ci (20.x)

`"` can be escaped with `&quot;`, `&ldquo;`, `&#34;`, `&rdquo;`
</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;

0 comments on commit e53e788

Please sign in to comment.