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(web-demo): add wasm miniscript to web demo #5340

Merged
merged 2 commits into from
Jan 8, 2025
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 modules/web-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
},
"dependencies": {
"@bitgo/key-card": "^0.23.43",
"@bitgo/abstract-utxo": "^9.10.0",
"@bitgo/sdk-api": "^1.57.6",
"@bitgo/sdk-coin-ada": "^4.5.3",
"@bitgo/sdk-coin-algo": "^2.1.55",
Expand Down
7 changes: 7 additions & 0 deletions modules/web-demo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const BGComponent = lazy(() => import('@components/BitGoJS'));
const BGApiComponent = lazy(() => import('@components/BitGoAPI'));
const CoinsComponent = lazy(() => import('@components/Coins'));
const KeyCardComponent = lazy(() => import('@components/KeyCard'));
const WasmMiniscriptComponent = lazy(
() => import('@components/WasmMiniscript'),
);
const EcdsaChallengeComponent = lazy(
() => import('@components/EcdsaChallenge'),
);
Expand All @@ -24,6 +27,10 @@ const App = () => {
<Route path="/bitgo-api" element={<BGApiComponent />} />
<Route path="/coins" element={<CoinsComponent />} />
<Route path="/keycard" element={<KeyCardComponent />} />
<Route
path="/wasm-miniscript"
element={<WasmMiniscriptComponent />}
/>
<Route
path="/ecdsachallenge"
element={<EcdsaChallengeComponent />}
Expand Down
6 changes: 6 additions & 0 deletions modules/web-demo/src/components/Navbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ const Navbar = () => {
>
Key Card
</NavItem>
<NavItem
activeRoute={pathname === '/wasm-miniscript'}
onClick={() => navigate('/wasm-miniscript')}
>
Wasm Miniscript
</NavItem>
<NavItem
activeRoute={pathname === '/ecdsachallenge'}
onClick={() => navigate('/ecdsachallenge')}
Expand Down
25 changes: 25 additions & 0 deletions modules/web-demo/src/components/WasmMiniscript/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React, { useState } from 'react';

import * as AbstractUtxo from '@bitgo/abstract-utxo';

const defaultDescriptor =
'wpkh(xpub661MyMwAqRbcFQpwd6c6aaioiXWuygdeknqE8v6PSNusNjwZypj1uXTVNysfsFPEDL6X3yS1kL6JeWyy9bAiR97Gz8KD9Z1W54uBw9U9j2t/*)';

export default function () {
const [descriptorString] = useState(defaultDescriptor);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: you do not need useState for this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to make this more interactive but didn't get around to it


const descriptor = AbstractUtxo.descriptor.Descriptor.fromString(
descriptorString,
'derivable',
);
return (
<div>
<pre>{descriptor.toString()}</pre>
<pre>
{Buffer.from(descriptor.atDerivationIndex(0).scriptPubkey()).toString(
'hex',
)}
</pre>
</div>
);
}
3 changes: 3 additions & 0 deletions modules/web-demo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
{
"path": "../bitgo"
},
{
"path": "../abstract-utxo"
},
{
"path": "../key-card"
},
Expand Down
4 changes: 4 additions & 0 deletions modules/web-demo/webpack/base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ const rules = [
emitFile: false,
},
},
{
test: /miniscript.*\.wasm$/,
type: 'webassembly/sync',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason webassembly/async does not work here. The import stays in some sort of deferred state.

},
];

const devRules = [
Expand Down
1 change: 1 addition & 0 deletions webpack/bitgojs.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ module.exports = {
experiments: {
backCompat: false,
asyncWebAssembly: true,
syncWebAssembly: true,
},
optimization: {
minimizer: [
Expand Down
Loading