Skip to content

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

Closed
wants to merge 2 commits into from

Conversation

lcovar
Copy link
Contributor

@lcovar lcovar commented Jun 25, 2025

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

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
…t, function or class

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@ppongbitgo ppongbitgo requested a review from Copilot June 25, 2025 21:29
Copy link

@Copilot Copilot AI left a 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
Copy link
Preview

Copilot AI Jun 25, 2025

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.

Comment on lines +21 to +25
export async function assertDescriptorWalletAddress(
network: utxolib.Network,
params: VerifyAddressOptions<UtxoCoinSpecific>,
descriptors: DescriptorMap
): void {
): Promise<void> {
Copy link
Preview

Copilot AI Jun 25, 2025

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.

Comment on lines +48 to +53
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');
Copy link
Preview

Copilot AI Jun 25, 2025

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.

@lcovar lcovar closed this Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants