Skip to content

Commit

Permalink
Decouples ledger-bitcoin from the library:
Browse files Browse the repository at this point in the history
- `ledger-bitcoin` is now a peer dependency. To use Ledger support, you need to install it separately. This change allows users to have control over the version of `ledger-bitcoin` they want to use and makes sure they are aware of the specific dependencies they are adding to their project. Additionally, if users are not interested in Ledger support, they can now omit `ledger-bitcoin` to minimize the size of their bundles.
- `AppClient` is no longer exported within `@bitcoinerlab/descriptors`. `AppClient` is the client library used to connect and interact with Ledger devices. Now, you need to import it directly from `ledger-bitcoin`. This change provides more clarity and control over where the dependencies are coming from.
  • Loading branch information
landabaso committed Jul 14, 2023
1 parent b98a0e7 commit 92be669
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 57 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.0] - 2023-07-14

### Changed

- `ledger-bitcoin` is now a peer dependency. To use Ledger support, you need to install it separately. This change allows users to have control over the version of `ledger-bitcoin` they want to use and makes sure they are aware of the specific dependencies they are adding to their project. Additionally, if users are not interested in Ledger support, they can now omit `ledger-bitcoin` to minimize the size of their bundles.

### Removed

- `AppClient` is no longer exported within `@bitcoinerlab/descriptors`. `AppClient` is the client library used to connect and interact with Ledger devices. Now, you need to import it directly from `ledger-bitcoin`. This change provides more clarity and control over where the dependencies are coming from.
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,28 +273,39 @@ To finalize the `psbt`, you can either call the method `finalizePsbtInput({ inde
This library currently provides integration with Ledger wallets. Support for more devices is planned.
To use a Ledger device for signing, you can import the necessary functions as follows:
Before we dive in, note that, in addition to the documentation below, it is highly recommended to visit the [Ledger Playground](https://bitcoinerlab.com/guides/ledger-programming) with an interactive code sandbox of this lib interacting with a Ledger device.
To use this library with Ledger devices, you must first install Ledger support:
```bash
npm install ledger-bitcoin
```
For Ledger device signing, import the necessary functions as follows:
```javascript
import Transport from '@ledgerhq/hw-transport-node-hid'; //or hw-transport-web-hid, for web
import { AppClient } from 'ledger-bitcoin';
import { ledger } from '@bitcoinerlab/descriptors';
```
You can then use the following code to assert that the Ledger app is running Bitcoin Test version 2.1.0 or higher, and to create a new Ledger client:
Then, use the following code to assert that the Ledger app is running Bitcoin Test version 2.1.0 or higher, and to create a new Ledger client:
```javascript
const transport = await Transport.create();
//Throws if not running Bitcoin Test >= 2.1.0
await ledger.assertLedgerApp({
transport,
name: 'Bitcoin Test',
minVersion: '2.1.0'
});
const ledgerClient = new ledger.AppClient(transport);
const ledgerClient = new AppClient(transport);
```
Here, `transport` is an instance of a Transport object that allows communication with Ledger devices. You can use any of the transports [provided by Ledger](https://github.com/LedgerHQ/ledger-live#libs---libraries).
To register the policies of non-standard descriptors on the Ledger device, you can use the following code:
To register the policies of non-standard descriptors on the Ledger device, use the following code:
```javascript
await ledger.registerLedgerWallet({
Expand All @@ -307,7 +318,7 @@ await ledger.registerLedgerWallet({
This code will auto-skip the policy registration process if it already exists. Please refer to [Ledger documentation](https://github.com/LedgerHQ/app-bitcoin-new/blob/develop/doc/wallet.md) to learn more about their Wallet Policies registration procedures.
Finally, `ledgerState` is an object used to store information related to Ledger devices. Although Ledger devices themselves are stateless, this object can be used to store information such as xpubs, master fingerprints, and wallet policies. You can pass an initially empty object that will be updated with more information as it is used. The object can be serialized and stored.
Finally, `ledgerState` is an object used to store information related to Ledger devices. Although Ledger devices themselves are stateless, this object can be used to store information such as xpubs, master fingerprints, and wallet policies. You can pass an initially empty object that will be updated with more information as it is used. The object can be serialized and stored for future use.
<a name="documentation"></a>
Expand Down
78 changes: 56 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions 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": "0.3.1",
"version": "1.0.0",
"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 Expand Up @@ -52,14 +52,20 @@
"files": [
"dist"
],
"COMMENT wrt ledger-bitcoin below": "ledger-bitcoin is installed using an alias. This package can be replaced with the official `ledger-bitcoin` npm package once [this PR](https://github.com/LedgerHQ/app-bitcoin-new/pull/147) is published to npm (likely in version > 0.2.1)",
"dependencies": {
"@bitcoinerlab/miniscript": "^1.2.1",
"@bitcoinerlab/secp256k1": "^1.0.2",
"bip32": "^3.1.0",
"bitcoinjs-lib": "^6.1.0",
"ecpair": "^2.1.0",
"ledger-bitcoin": "npm:@bitcoinerlab/ledger@^0.2.0"
"ecpair": "^2.1.0"
},
"peerDependencies": {
"ledger-bitcoin": "^0.2.2"
},
"peerDependenciesMeta": {
"ledger-bitcoin": {
"optional": true
}
},
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.20.11",
Expand All @@ -77,6 +83,7 @@
"fs": "^0.0.1-security",
"jest": "^29.4.3",
"jsdoc": "^3.6.11",
"ledger-bitcoin": "^0.2.2",
"path": "^0.12.7",
"prettier": "^2.8.8",
"regtest-client": "^0.2.0",
Expand Down
4 changes: 1 addition & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export { keyExpressionBIP32, keyExpressionLedger } from './keyExpressions';
import * as scriptExpressions from './scriptExpressions';
export { scriptExpressions };

import { AppClient } from 'ledger-bitcoin';
import {
LedgerState,
getLedgerMasterFingerPrint,
Expand All @@ -44,8 +43,7 @@ export const ledger = {
getLedgerMasterFingerPrint,
getLedgerXpub,
registerLedgerWallet,
assertLedgerApp,
AppClient
assertLedgerApp
};

export type { LedgerState };
Loading

0 comments on commit 92be669

Please sign in to comment.