Skip to content

Commit

Permalink
Further document public functions
Browse files Browse the repository at this point in the history
  • Loading branch information
landabaso committed Oct 19, 2023
1 parent 28fea64 commit 388ceef
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/descriptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ export function DescriptorsFactory(ecc: TinySecp256k1Interface) {
signersPubKeys
}: {
/**
* The descriptor string in ASCII format. It may include a "*" to denote an arbitrary index.
* The descriptor string in ASCII format. It may include a "*" to denote an arbitrary index (aka ranged descriptors).
*/
descriptor: string;

Expand All @@ -572,7 +572,7 @@ export function DescriptorsFactory(ecc: TinySecp256k1Interface) {
index?: number;

/**
* A flag indicating whether the descriptor is required to include a checksum.
* An optional flag indicating whether the descriptor is required to include a checksum.
* @defaultValue false
*/
checksumRequired?: boolean;
Expand Down Expand Up @@ -607,6 +607,8 @@ export function DescriptorsFactory(ecc: TinySecp256k1Interface) {
* the public keys involved in the descriptor will sign the transaction.
* In the latter case, the satisfier will automatically choose the most
* optimal spending path (if more than one is available).
* For more details on using this parameter, refer to [this Stack Exchange
* answer](https://bitcoin.stackexchange.com/a/118036/89665).
*/
signersPubKeys?: Buffer[];
}) {
Expand Down Expand Up @@ -910,7 +912,10 @@ export function DescriptorsFactory(ecc: TinySecp256k1Interface) {
validate = true
}: {
psbt: Psbt;
/** @default true */
/** Runs further test on the validity of the signatures.
* It speeds down the finalization process but makes sure the psbt will
* be valid.
* @default true */
validate?: boolean | undefined;
}) => this.finalizePsbtInput({ index, psbt, validate });
return finalizer;
Expand Down Expand Up @@ -1003,7 +1008,10 @@ export function DescriptorsFactory(ecc: TinySecp256k1Interface) {
}: {
index: number;
psbt: Psbt;
/** @default true */
/** Runs further test on the validity of the signatures.
* It speeds down the finalization process but makes sure the psbt will
* be valid.
* @default true */
validate?: boolean | undefined;
}): void {
if (
Expand Down
19 changes: 19 additions & 0 deletions src/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,33 @@ async function ledgerAppInfo(transport: any) {
return { name, version, flags, format };
}

/**
* Verifies if the Ledger device is connected, if the required Bitcoin App is opened,
* and if the version of the app meets the minimum requirements.
*
* @throws Will throw an error if the Ledger device is not connected, the required
* Bitcoin App is not opened, or if the version is below the required number.
*
* @returns Promise<void> - A promise that resolves if all assertions pass, or throws otherwise.
*/
export async function assertLedgerApp({
transport,
name,
minVersion
}: {
/**
* Connection transport with the Ledger device.
* One of these: https://github.com/LedgerHQ/ledger-live#libs---libraries
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
transport: any;
/**
* The name of the Bitcoin App. "Bitcoin" for mainnet or "Bitcoin Test" for testnet.
*/
name: string;
/**
* The minimum acceptable version of the Bitcoin App in semver format (major.minor.patch).
*/
minVersion: string;
}): Promise<void> {
const { name: openName, version } = await ledgerAppInfo(transport);
Expand Down

0 comments on commit 388ceef

Please sign in to comment.