-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for the BitBox02 hardware wallet (#117)
* add support for the BitBox02 hardware wallet Using the `bitbox-api` NPM package, which loads a WASM module. Note about CJS: Currently the `bitbox-api` package is an ESM package with a `module: ...` entrypoint, so it is not compatible with the `cjs` target of caravan-wallets. The only workaround that I could find where compilation succeeds and the package works in the browser is to mark bitbox-api as external in tsup.config.ts. Note about signing tests: - The BitBox02 requires the previous transaction of each input to be present in the PSBT (`PSBT_IN_NON_WITNESS_UTXO`), so it can verify the input amount and avoid fee attacks. The signing test fixtures are missing these, so they fail. - The BitBox02 uses the anti-klepto (anti-exfil) protocol to mitigate covert nonce exfil attacks. This results in random signatures. The unit test fixtures hardcode the expected signatures, assuming they are always the same. As a result, also here the tests fail. To fix this, the tests should rather verify the ECDSA signatures against the transaction sighash for each input. * hide BitBox02 menu item for P2SH BitBox02 does not support legacy P2SH. * bitbox: display pairing code The BitBox, if not paired yet, will show a pairing code for confirmation. This can happen in any BitBox interaction. This commit adds a `showPairingCode` param to all BitBox interactions. If not provided, a default implementation is used which shows the pairing code in a browser popup. The current `messages()` system is not a good fit, as the client does not know when to call `messagesFor()` to display it. Having a separate UI button to pair the BitBox is not good UX (why should the user be bothered to click a "pair" button first? What if the user doesn't) and also fragile (a re-pairing could be needed at any time). * add regtest support for BitBox02 --------- Co-authored-by: buck <[email protected]>
- Loading branch information
Showing
24 changed files
with
749 additions
and
13 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,6 @@ | ||
--- | ||
"@caravan/wallets": minor | ||
"caravan-coordinator": minor | ||
--- | ||
|
||
Add support for the BitBox02 hardware wallet |
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
39 changes: 39 additions & 0 deletions
39
apps/coordinator/src/components/RegisterWallet/RegisterBitBoxButton.jsx
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,39 @@ | ||
import React, { useState } from "react"; | ||
import { Button } from "@mui/material"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { BITBOX, RegisterWalletPolicy } from "@caravan/wallets"; | ||
import { getWalletConfig } from "../../selectors/wallet"; | ||
import { setErrorNotification } from "../../actions/errorNotificationActions"; | ||
|
||
const RegisterBitBoxButton = ({ ...otherProps }) => { | ||
const [isActive, setIsActive] = useState(false); | ||
const walletConfig = useSelector(getWalletConfig); | ||
const dispatch = useDispatch(); | ||
|
||
const registerWallet = async () => { | ||
setIsActive(true); | ||
try { | ||
const interaction = new RegisterWalletPolicy({ | ||
keystore: BITBOX, | ||
...walletConfig, | ||
}); | ||
await interaction.run(); | ||
} catch (e) { | ||
dispatch(setErrorNotification(e.message)); | ||
} finally { | ||
setIsActive(false); | ||
} | ||
}; | ||
return ( | ||
<Button | ||
variant="outlined" | ||
onClick={registerWallet} | ||
disabled={isActive} | ||
{...otherProps} | ||
> | ||
Register w/ BitBox | ||
</Button> | ||
); | ||
}; | ||
|
||
export default RegisterBitBoxButton; |
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,9 +1,11 @@ | ||
import DownloadColdardConfigButton from "./DownloadColdcardConfig"; | ||
import PolicyRegistrationTable from "./PolicyRegistrationsTable"; | ||
import RegisterBitBoxButton from "./RegisterBitBoxButton"; | ||
import RegisterLedgerButton from "./RegisterLedgerButton"; | ||
|
||
export { | ||
DownloadColdardConfigButton, | ||
PolicyRegistrationTable, | ||
RegisterBitBoxButton, | ||
RegisterLedgerButton, | ||
}; |
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
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
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,13 @@ | ||
import { BITBOX } from "@caravan/wallets"; | ||
|
||
import publicKeyTests from "./publicKeys"; | ||
import extendedPublicKeyTests from "./extendedPublicKeys"; | ||
import { signingTests } from "./signing"; | ||
import addressTests from "./addresses"; | ||
import registrationTests from "./registration"; | ||
|
||
export default publicKeyTests(BITBOX) | ||
.concat(extendedPublicKeyTests(BITBOX)) | ||
.concat(signingTests(BITBOX)) | ||
.concat(addressTests(BITBOX)) | ||
.concat(registrationTests(BITBOX)); |
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
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.