From ab6cda11921e540ab997648099ed05c65ba3b72d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Landabaso=20D=C3=ADaz?= Date: Mon, 17 Jul 2023 09:41:05 +0200 Subject: [PATCH] Bump version to 1.0.2 and update importAndValidateLedgerBitcoin function - Bump version in package.json to 1.0.2 - Modify importAndValidateLedgerBitcoin function to return Promise rather than Promise to prevent breaking projects that don't use ledger-bitcoin as a dependency - Adjusted function invocations across ledger.ts and signers.ts to cast the returned promise to expected type --- package.json | 2 +- src/ledger.ts | 18 ++++++++++++------ src/signers.ts | 8 ++++++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index df5e56c..ac13194 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@bitcoinerlab/descriptors", "homepage": "https://github.com/bitcoinerlab/descriptors", - "version": "1.0.1", + "version": "1.0.2", "description": "This library parses and creates Bitcoin Miniscript Descriptors and generates Partially Signed Bitcoin Transactions (PSBTs). It provides PSBT finalizers and signers for single-signature, BIP32 and Hardware Wallets.", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/ledger.ts b/src/ledger.ts index f2a9d63..302bdb0 100644 --- a/src/ledger.ts +++ b/src/ledger.ts @@ -35,7 +35,7 @@ import { reOriginPath } from './re'; * @param {unknown} ledgerClient - An optional parameter that, if provided, is checked to see if it's an instance of `AppClient`. * @throws {Error} Throws an error if `ledgerClient` is provided but is not an instance of `AppClient`. * @throws {Error} Throws an error if the 'ledger-bitcoin' module cannot be imported. This typically indicates that the 'ledger-bitcoin' peer dependency is not installed. - * @returns {Promise} Returns a promise that resolves with the entire 'ledger-bitcoin' module if it can be successfully imported. + * @returns {Promise} Returns a promise that resolves with the entire 'ledger-bitcoin' module if it can be successfully imported. We force it to return an unknown type so that the declaration of this function won't break projects that don't use ledger-bitcoin as dependency * * @example * @@ -46,7 +46,9 @@ import { reOriginPath } from './re'; * }) * .catch((error) => console.error(error)); */ -export async function importAndValidateLedgerBitcoin(ledgerClient?: unknown) { +export async function importAndValidateLedgerBitcoin( + ledgerClient?: unknown +): Promise { let ledgerBitcoinModule; try { ledgerBitcoinModule = await import('ledger-bitcoin'); @@ -160,7 +162,9 @@ export async function getLedgerMasterFingerPrint({ ledgerClient: unknown; ledgerState: LedgerState; }): Promise { - const { AppClient } = await importAndValidateLedgerBitcoin(ledgerClient); + const { AppClient } = (await importAndValidateLedgerBitcoin( + ledgerClient + )) as typeof import('ledger-bitcoin'); if (!(ledgerClient instanceof AppClient)) throw new Error(`Error: pass a valid ledgerClient`); let masterFingerprint = ledgerState.masterFingerprint; @@ -182,7 +186,9 @@ export async function getLedgerXpub({ ledgerClient: unknown; ledgerState: LedgerState; }): Promise { - const { AppClient } = await importAndValidateLedgerBitcoin(ledgerClient); + const { AppClient } = (await importAndValidateLedgerBitcoin( + ledgerClient + )) as typeof import('ledger-bitcoin'); if (!(ledgerClient instanceof AppClient)) throw new Error(`Error: pass a valid ledgerClient`); if (!ledgerState.xpubs) ledgerState.xpubs = {}; @@ -333,9 +339,9 @@ export async function registerLedgerWallet({ ledgerState: LedgerState; policyName: string; }) { - const { WalletPolicy, AppClient } = await importAndValidateLedgerBitcoin( + const { WalletPolicy, AppClient } = (await importAndValidateLedgerBitcoin( ledgerClient - ); + )) as typeof import('ledger-bitcoin'); if (!(ledgerClient instanceof AppClient)) throw new Error(`Error: pass a valid ledgerClient`); const result = await descriptorToLedgerFormat({ diff --git a/src/signers.ts b/src/signers.ts index 36af980..f8cfbe6 100644 --- a/src/signers.ts +++ b/src/signers.ts @@ -91,7 +91,9 @@ export async function signInputLedger({ ledgerState: LedgerState; }): Promise { const { PsbtV2, DefaultWalletPolicy, WalletPolicy, AppClient } = - await importAndValidateLedgerBitcoin(ledgerClient); + (await importAndValidateLedgerBitcoin( + ledgerClient + )) as typeof import('ledger-bitcoin'); if (!(ledgerClient instanceof AppClient)) throw new Error(`Error: pass a valid ledgerClient`); @@ -161,7 +163,9 @@ export async function signLedger({ ledgerState: LedgerState; }): Promise { const { PsbtV2, DefaultWalletPolicy, WalletPolicy, AppClient } = - await importAndValidateLedgerBitcoin(ledgerClient); + (await importAndValidateLedgerBitcoin( + ledgerClient + )) as typeof import('ledger-bitcoin'); if (!(ledgerClient instanceof AppClient)) throw new Error(`Error: pass a valid ledgerClient`); const ledgerPolicies = [];