diff --git a/.changeset/new-seas-vanish.md b/.changeset/new-seas-vanish.md index 5528c218..5a5f6bc2 100644 --- a/.changeset/new-seas-vanish.md +++ b/.changeset/new-seas-vanish.md @@ -1,6 +1,5 @@ --- -"@caravan/descriptors": major -"@caravan/coordinator": patch +"@caravan/descriptors": minor --- -Add new package for encoding and decoding descriptors using bdk with wasm bindings. Adds initial usage of descriptors in coordinator +Add new package for encoding and decoding descriptors using bdk with wasm bindings. diff --git a/apps/coordinator/package.json b/apps/coordinator/package.json index 429569df..f7c3e3ff 100644 --- a/apps/coordinator/package.json +++ b/apps/coordinator/package.json @@ -62,8 +62,7 @@ "standard-version": "^9.0.0", "typescript": "^5.0.2", "vite": "^4.2.3", - "vite-plugin-node-polyfills": "^0.7.0", - "vite-plugin-wasm": "^3.3.0" + "vite-plugin-node-polyfills": "^0.7.0" }, "scripts": { "build": "npm run check && tsc && __GIT_SHA__=`git rev-parse --short HEAD` vite build", @@ -95,7 +94,6 @@ "dependencies": { "@caravan/bitcoin": "*", "@caravan/clients": "*", - "@caravan/descriptors": "*", "@caravan/wallets": "*", "@emotion/react": "^11.10.6", "@emotion/styled": "^11.10.6", diff --git a/apps/coordinator/src/components/Wallet/DownloadDescriptors.tsx b/apps/coordinator/src/components/Wallet/DownloadDescriptors.tsx deleted file mode 100644 index e1f12837..00000000 --- a/apps/coordinator/src/components/Wallet/DownloadDescriptors.tsx +++ /dev/null @@ -1,53 +0,0 @@ -import React, { useEffect, useState } from "react"; - -import { useSelector } from "react-redux"; -import { Button } from "@mui/material"; -import { getMaskedDerivation } from "@caravan/bitcoin"; -import { encodeDescriptors } from "@caravan/descriptors"; -import { getWalletConfig } from "../../selectors/wallet"; -import { downloadFile } from "../../utils"; -import { KeyOrigin } from "@caravan/wallets"; - -export const DownloadDescriptors = () => { - const walletConfig = useSelector(getWalletConfig); - const [descriptors, setDescriptors] = useState({ change: "", receive: "" }); - - useEffect(() => { - const loadAsync = async () => { - const multisigConfig = { - requiredSigners: walletConfig.quorum.requiredSigners, - keyOrigins: walletConfig.extendedPublicKeys.map( - ({ xfp, bip32Path, xpub }: KeyOrigin) => ({ - xfp, - bip32Path: getMaskedDerivation({ xpub, bip32Path }), - xpub, - }), - ), - addressType: walletConfig.addressType, - network: walletConfig.network, - }; - const { change, receive } = await encodeDescriptors(multisigConfig); - setDescriptors({ change, receive }); - }; - loadAsync(); - }, []); - - const handleDownload = () => { - if (descriptors.change) { - downloadFile( - JSON.stringify(descriptors, null, 2), - `${walletConfig.uuid}.txt`, - ); - } - }; - - return ( - - ); -}; diff --git a/apps/coordinator/src/components/Wallet/WalletConfigInteractionButtons.jsx b/apps/coordinator/src/components/Wallet/WalletConfigInteractionButtons.jsx index 9d9d20ca..8d38b147 100644 --- a/apps/coordinator/src/components/Wallet/WalletConfigInteractionButtons.jsx +++ b/apps/coordinator/src/components/Wallet/WalletConfigInteractionButtons.jsx @@ -2,7 +2,6 @@ import React from "react"; import PropTypes from "prop-types"; import { Button, Grid } from "@mui/material"; import { CARAVAN_CONFIG } from "./constants"; -import { DownloadDescriptors } from "./DownloadDescriptors"; const WalletConfigInteractionButtons = ({ onClearFn, onDownloadFn }) => { const handleClearClick = (e) => { @@ -27,9 +26,6 @@ const WalletConfigInteractionButtons = ({ onClearFn, onDownloadFn }) => { Clear Wallet - - - ); }; diff --git a/apps/coordinator/src/components/Wallet/WalletDescriptorImporter.tsx b/apps/coordinator/src/components/Wallet/WalletDescriptorImporter.tsx deleted file mode 100644 index 201d66c6..00000000 --- a/apps/coordinator/src/components/Wallet/WalletDescriptorImporter.tsx +++ /dev/null @@ -1,88 +0,0 @@ -import React, { Dispatch, useEffect, useState } from "react"; -import { Button } from "@mui/material"; -import { useDispatch, useSelector } from "react-redux"; - -import type { KeyOrigin, MultisigWalletConfig } from "@caravan/descriptors"; -import { getWalletFromDescriptor, getChecksum } from "@caravan/descriptors"; -import { - setRequiredSigners, - setTotalSigners, -} from "../../actions/transactionActions"; -import { setAddressType } from "../../actions/settingsActions"; -import { - setExtendedPublicKeyImporterBIP32Path, - setExtendedPublicKeyImporterExtendedPublicKey, - setExtendedPublicKeyImporterExtendedPublicKeyRootFingerprint, - setExtendedPublicKeyImporterFinalized, - setExtendedPublicKeyImporterMethod, - setExtendedPublicKeyImporterName, -} from "../../actions/extendedPublicKeyImporterActions"; -import { updateWalletUuidAction } from "../../actions/walletActions"; -import { BitcoinNetwork, MultisigAddressType } from "@caravan/bitcoin"; - -const importWalletDetails = ( - { - keyOrigins, - requiredSigners, - addressType, - }: { - keyOrigins: KeyOrigin[]; - requiredSigners: number; - addressType: MultisigAddressType; - }, - dispatch: Dispatch, -) => { - dispatch(setTotalSigners(keyOrigins.length)); - dispatch(setRequiredSigners(requiredSigners)); - dispatch(setAddressType(addressType)); - keyOrigins.forEach(({ xfp, bip32Path, xpub }, index) => { - const number = index + 1; - dispatch(setExtendedPublicKeyImporterName(number, `key_${number}_${xfp}`)); - dispatch(setExtendedPublicKeyImporterMethod(number, "text")); - dispatch(setExtendedPublicKeyImporterBIP32Path(number, bip32Path)); - dispatch( - setExtendedPublicKeyImporterExtendedPublicKeyRootFingerprint(number, xfp), - ); - dispatch(setExtendedPublicKeyImporterExtendedPublicKey(number, xpub)); - dispatch(setExtendedPublicKeyImporterFinalized(number, true)); - }); -}; - -export const WalletDescriptorImporter = () => { - const [walletConfig, setWalletConfig] = useState(); - const network = useSelector( - (state: { quorum: { network: BitcoinNetwork } }) => state.quorum.network, - ); - const dispatch = useDispatch(); - useEffect(() => { - if (walletConfig) { - importWalletDetails(walletConfig, dispatch); - } - }, [walletConfig]); - - const handleClick = async () => { - // eslint-disable-next-line no-alert - const descriptor = window.prompt( - `Please enter one of the wallet's descriptors (change or receive). -Make sure any settings that are not in a descriptor are set before submitting.`, - ); - - if (descriptor) { - try { - const config = await getWalletFromDescriptor(descriptor, network); - const checksum = await getChecksum(descriptor); - dispatch(updateWalletUuidAction(checksum)); - setWalletConfig(config); - } catch (e) { - // eslint-disable-next-line no-alert - window.alert(e.message); - } - } - }; - - return ( - - ); -}; diff --git a/apps/coordinator/src/components/Wallet/index.jsx b/apps/coordinator/src/components/Wallet/index.jsx index ff0417e7..67d1b5c4 100644 --- a/apps/coordinator/src/components/Wallet/index.jsx +++ b/apps/coordinator/src/components/Wallet/index.jsx @@ -58,7 +58,6 @@ import { SET_CLIENT_USERNAME, } from "../../actions/clientActions"; import { clientPropTypes, slicePropTypes } from "../../proptypes"; -import { WalletDescriptorImporter } from "./WalletDescriptorImporter"; class CreateWallet extends React.Component { static validateProperties(config, properties, key) { @@ -540,9 +539,6 @@ class CreateWallet extends React.Component { {this.renderWalletImporter()} - - - diff --git a/apps/coordinator/vite.config.ts b/apps/coordinator/vite.config.ts index 7bbefc44..328d6433 100644 --- a/apps/coordinator/vite.config.ts +++ b/apps/coordinator/vite.config.ts @@ -2,7 +2,6 @@ import { defineConfig } from "vite"; import react from "@vitejs/plugin-react"; import { nodePolyfills } from "vite-plugin-node-polyfills"; import path from "path"; -import wasm from "vite-plugin-wasm"; // https://vitejs.dev/config/ export default defineConfig({ @@ -11,14 +10,12 @@ export default defineConfig({ // then the sub-path can cause issues base: process.env.GH_PAGES || process.env.GITHUB_ACTIONS ? "/caravan/#" : "/#", - assetsInclude: ["**/*.wasm"], resolve: { alias: { utils: path.resolve(__dirname, "./src/utils"), }, }, plugins: [ - wasm(), react(), nodePolyfills({ protocolImports: true, @@ -39,8 +36,4 @@ export default defineConfig({ __GIT_SHA__: JSON.stringify(process.env.__GIT_SHA__), __APP_VERSION__: JSON.stringify(process.env.npm_package_version), }, - optimizeDeps: { - // needed for local development to support proper handling of wasm - exclude: ["@caravan/descriptors"], - }, }); diff --git a/package-lock.json b/package-lock.json index a6918b4f..fabe2a12 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,7 +28,6 @@ "dependencies": { "@caravan/bitcoin": "*", "@caravan/clients": "*", - "@caravan/descriptors": "*", "@caravan/wallets": "*", "@emotion/react": "^11.10.6", "@emotion/styled": "^11.10.6", @@ -116,8 +115,7 @@ "standard-version": "^9.0.0", "typescript": "^5.0.2", "vite": "^4.2.3", - "vite-plugin-node-polyfills": "^0.7.0", - "vite-plugin-wasm": "^3.3.0" + "vite-plugin-node-polyfills": "^0.7.0" }, "engines": { "node": ">=20" @@ -23404,15 +23402,6 @@ "vite": "^2.0.0 || ^3.0.0 || ^4.0.0" } }, - "node_modules/vite-plugin-wasm": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/vite-plugin-wasm/-/vite-plugin-wasm-3.3.0.tgz", - "integrity": "sha512-tVhz6w+W9MVsOCHzxo6SSMSswCeIw4HTrXEi6qL3IRzATl83jl09JVO1djBqPSwfjgnpVHNLYcaMbaDX5WB/pg==", - "dev": true, - "peerDependencies": { - "vite": "^2 || ^3 || ^4 || ^5" - } - }, "node_modules/vite/node_modules/rollup": { "version": "3.29.4", "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.29.4.tgz",