Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: bip32 package with blinded xpub support #126

Merged
merged 19 commits into from
Sep 9, 2024
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
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: (
extendedPublicKey: string,
errCb: (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 disappear once you hit &quot;Enter&quot;.
</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;
Loading
Loading