Skip to content

Commit

Permalink
Bump version to 1.0.2 and update importAndValidateLedgerBitcoin function
Browse files Browse the repository at this point in the history
- Bump version in package.json to 1.0.2
- Modify importAndValidateLedgerBitcoin function to return Promise<unknown> rather than Promise<any> 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
  • Loading branch information
landabaso committed Jul 17, 2023
1 parent 2a97b62 commit ab6cda1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
18 changes: 12 additions & 6 deletions src/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>} Returns a promise that resolves with the entire 'ledger-bitcoin' module if it can be successfully imported.
* @returns {Promise<unknown>} 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
*
Expand All @@ -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<unknown> {
let ledgerBitcoinModule;
try {
ledgerBitcoinModule = await import('ledger-bitcoin');
Expand Down Expand Up @@ -160,7 +162,9 @@ export async function getLedgerMasterFingerPrint({
ledgerClient: unknown;
ledgerState: LedgerState;
}): Promise<Buffer> {
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;
Expand All @@ -182,7 +186,9 @@ export async function getLedgerXpub({
ledgerClient: unknown;
ledgerState: LedgerState;
}): Promise<string> {
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 = {};
Expand Down Expand Up @@ -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({
Expand Down
8 changes: 6 additions & 2 deletions src/signers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ export async function signInputLedger({
ledgerState: LedgerState;
}): Promise<void> {
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`);

Expand Down Expand Up @@ -161,7 +163,9 @@ export async function signLedger({
ledgerState: LedgerState;
}): Promise<void> {
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 = [];
Expand Down

0 comments on commit ab6cda1

Please sign in to comment.