-
Notifications
You must be signed in to change notification settings - Fork 296
feat(BTC-0-1): convert imports to dynamic for @bitgo/wasm-miniscript #6354
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
Conversation
…t, function or class Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors direct imports from @bitgo/wasm-miniscript
to dynamic imports for better code splitting and lazy loading, converting several descriptor-related functions to async.
- Convert descriptor parsing, building, validation, and signature utilities to use
import()
dynamically. - Update validation policy functions (
validate
,assertDescriptorPolicy
,toDescriptorMapValidate
) to return Promises. - Remove direct exports of
Descriptor
/Miniscript
from the module index.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
modules/abstract-utxo/src/descriptor/validatePolicy.ts | Made all validate methods async and return Promise<boolean> |
modules/abstract-utxo/src/descriptor/index.ts | Removed direct @bitgo/wasm-miniscript exports |
modules/abstract-utxo/src/descriptor/builder/parse.ts | Changed parseDescriptor to async and awaited builder exports |
modules/abstract-utxo/src/descriptor/builder/builder.ts | Made getDescriptorFromBuilder async with dynamic import |
modules/abstract-utxo/src/descriptor/assertDescriptorWalletAddress.ts | Marked function async (no await inside) |
modules/abstract-utxo/src/descriptor/NamedDescriptor.ts | Updated creation, conversion, and signature checks to async |
@@ -1,4 +1,5 @@ | |||
export { Miniscript, Descriptor } from '@bitgo/wasm-miniscript'; | |||
// Changed from direct import to async import pattern |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The re-exports for Descriptor
and Miniscript
were removed but not replaced with dynamic loader functions, breaking existing consumers. Consider adding async helper functions or re-export wrappers that load and expose these symbols at runtime.
Copilot uses AI. Check for mistakes.
export async function assertDescriptorWalletAddress( | ||
network: utxolib.Network, | ||
params: VerifyAddressOptions<UtxoCoinSpecific>, | ||
descriptors: DescriptorMap | ||
): void { | ||
): Promise<void> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is marked async
but contains no await
or dynamic imports. Consider removing async
to keep the signature synchronous or reintroduce the intended dynamic import for Descriptor
.
Copilot uses AI. Check for mistakes.
const { Descriptor } = await import('@bitgo/wasm-miniscript'); | ||
return { ...e, value: Descriptor.fromString(e.value, pkType) }; | ||
} | ||
|
||
export function hasValidSignature(descriptor: string | Descriptor, key: BIP32Interface, signatures: string[]): boolean { | ||
export async function hasValidSignature(descriptor: string | Descriptor, key: BIP32Interface, signatures: string[]): Promise<boolean> { | ||
const { Descriptor } = await import('@bitgo/wasm-miniscript'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dynamic import of @bitgo/wasm-miniscript
occurs every call. For better performance, hoist the dynamic import outside loops or cache the imported module so it's only loaded once per runtime.
Copilot uses AI. Check for mistakes.
Convert direct imports of Descriptor and DescriptorPkType from @bitgo/wasm-miniscript to dynamic imports for better code splitting and lazy loading. This makes functions async and prevents the library from being loaded until needed.
Ticket: BTC-0
TICKET: BTC-0