@ledgerhq/device-signer-kit-bitcoin 0.0.0-signer-eth-20250122093657 → 0.0.0-webhid-20250124103640
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +100 -32
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -9,16 +9,17 @@ This module provides the implementation of the Ledger Bitcoin signer of the Devi
|
|
|
9
9
|
|
|
10
10
|
## 🔹 Index
|
|
11
11
|
|
|
12
|
-
1. [How it works](
|
|
13
|
-
2. [Installation](
|
|
14
|
-
3. [Initialisation](
|
|
15
|
-
4. [Use Cases](
|
|
12
|
+
1. [How it works](#-how-it-works)
|
|
13
|
+
2. [Installation](#-installation)
|
|
14
|
+
3. [Initialisation](#-initialisation)
|
|
15
|
+
4. [Use Cases](#-use-cases)
|
|
16
16
|
- [Get Extended Public Key](#use-case-1-get-extended-public-key)
|
|
17
17
|
- [Sign Message](#use-case-2-sign-message)
|
|
18
18
|
- [Sign Partially Signed Transaction (PSBT)](#use-case-3-sign-psbt)
|
|
19
19
|
- [Sign Transaction](#use-case-4-sign-transaction)
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
- [Get Wallet address](#use-case-5-get-wallet-address)
|
|
21
|
+
5. [Observable Behavior](#-observable-behavior)
|
|
22
|
+
6. [Example](#-example)
|
|
22
23
|
|
|
23
24
|
## 🔹 How it works
|
|
24
25
|
|
|
@@ -39,7 +40,7 @@ npm install @ledgerhq/device-signer-kit-bitcoin
|
|
|
39
40
|
To initialise a Bitcoin signer instance, you need a Ledger Device Management Kit instance and the ID of the session of the connected device. Use the `SignerBtcBuilder` along with the [Context Module](https://github.com/LedgerHQ/device-sdk-ts/tree/develop/packages/signer/context-module) by default developed by Ledger:
|
|
40
41
|
|
|
41
42
|
```typescript
|
|
42
|
-
//
|
|
43
|
+
// Initialise a Bitcoin signer instance
|
|
43
44
|
const signerBitcoin = new SignerBtcBuilder({ sdk, sessionId }).build();
|
|
44
45
|
```
|
|
45
46
|
|
|
@@ -49,7 +50,7 @@ The `SignerBtcBuilder.build()` method will return a `SignerBitcoin` instance tha
|
|
|
49
50
|
|
|
50
51
|
---
|
|
51
52
|
|
|
52
|
-
### Use Case 1: Get
|
|
53
|
+
### Use Case 1: Get extended public key
|
|
53
54
|
|
|
54
55
|
This method allows users to retrieve the Bitcoin extended public key based on a given `derivationPath`.
|
|
55
56
|
|
|
@@ -65,7 +66,7 @@ const { observable, cancel } = signerBitcoin.getExtendedPublicKey(
|
|
|
65
66
|
- `derivationPath`
|
|
66
67
|
|
|
67
68
|
- **Required**
|
|
68
|
-
- **Type:** `string` (e.g. `"84'/0'/0'"` for a Native
|
|
69
|
+
- **Type:** `string` (e.g. `"84'/0'/0'"` for a Native SegWit wallet)
|
|
69
70
|
- The derivation path used for the Bitcoin address. See [here](https://www.ledger.com/blog/understanding-crypto-addresses-and-derivation-paths) for more information.
|
|
70
71
|
|
|
71
72
|
- `options`
|
|
@@ -83,7 +84,7 @@ const { observable, cancel } = signerBitcoin.getExtendedPublicKey(
|
|
|
83
84
|
|
|
84
85
|
#### **Returns**
|
|
85
86
|
|
|
86
|
-
- `observable` Emits DeviceActionState updates, including the following details
|
|
87
|
+
- `observable` Emits DeviceActionState updates, including the following details:
|
|
87
88
|
|
|
88
89
|
```typescript
|
|
89
90
|
type GetAddressCommandResponse = {
|
|
@@ -95,7 +96,7 @@ type GetAddressCommandResponse = {
|
|
|
95
96
|
|
|
96
97
|
---
|
|
97
98
|
|
|
98
|
-
### Use Case 2: Sign
|
|
99
|
+
### Use Case 2: Sign message
|
|
99
100
|
|
|
100
101
|
This method allows users to sign a text string that is displayed on Ledger devices.
|
|
101
102
|
|
|
@@ -111,18 +112,18 @@ const { observable, cancel } = signerBitcoin.signMessage(
|
|
|
111
112
|
- `derivationPath`
|
|
112
113
|
|
|
113
114
|
- **Required**
|
|
114
|
-
- **Type:** `string` (e.g. `"84'/0'/0'"` for a Native
|
|
115
|
+
- **Type:** `string` (e.g. `"84'/0'/0'"` for a Native SegWit wallet)
|
|
115
116
|
- The derivation path used for the Bitcoin address. See [here](https://www.ledger.com/blog/understanding-crypto-addresses-and-derivation-paths) for more information.
|
|
116
117
|
|
|
117
118
|
- `message`
|
|
118
119
|
|
|
119
120
|
- **Required**
|
|
120
|
-
- **Type
|
|
121
|
+
- **Type:** `string`
|
|
121
122
|
- The message to be signed, which will be displayed on the Ledger device.
|
|
122
123
|
|
|
123
124
|
#### **Returns**
|
|
124
125
|
|
|
125
|
-
- `observable` Emits DeviceActionState updates, including the following details
|
|
126
|
+
- `observable` Emits DeviceActionState updates, including the following details:
|
|
126
127
|
|
|
127
128
|
```typescript
|
|
128
129
|
type Signature = {
|
|
@@ -159,7 +160,7 @@ const { observable, cancel } = signerBitcoin.signPsbt(
|
|
|
159
160
|
|
|
160
161
|
class DefaultWallet {
|
|
161
162
|
constructor(
|
|
162
|
-
// Derivation path without master key
|
|
163
|
+
// Derivation path without master key representation.
|
|
163
164
|
// Format example: /44'/0'/0'
|
|
164
165
|
public derivationPath: string,
|
|
165
166
|
public template: DefaultDescriptorTemplate,
|
|
@@ -178,19 +179,38 @@ const { observable, cancel } = signerBitcoin.signPsbt(
|
|
|
178
179
|
|
|
179
180
|
- `psbt`
|
|
180
181
|
- **Required**
|
|
181
|
-
- **Type:** `string`
|
|
182
|
-
-
|
|
182
|
+
- **Type:** `string | Psbt`
|
|
183
|
+
- A base64/hex psbt string or [bitcoin-js Psbt](https://github.com/bitcoinjs/bitcoinjs-lib/blob/151173f05e26a9af7c98d8d1e3f90e97185955f1/ts_src/psbt.ts#L131)
|
|
183
184
|
|
|
184
185
|
#### **Returns**
|
|
185
186
|
|
|
186
|
-
- `observable` Emits DeviceActionState updates, including the following details
|
|
187
|
+
- `observable` Emits DeviceActionState updates, including the following details:
|
|
187
188
|
|
|
188
189
|
```typescript
|
|
189
|
-
type
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
190
|
+
type PartialSignature = {
|
|
191
|
+
inputIndex: number;
|
|
192
|
+
pubkey: Uint8Array;
|
|
193
|
+
signature: Uint8Array;
|
|
194
|
+
tapleafHash?: Uint8Array;
|
|
193
195
|
};
|
|
196
|
+
|
|
197
|
+
type MusigPubNonce = {
|
|
198
|
+
inputIndex: number;
|
|
199
|
+
participantPubkey: Uint8Array;
|
|
200
|
+
aggregatedPubkey: Uint8Array;
|
|
201
|
+
tapleafHash: Uint8Array;
|
|
202
|
+
pubnonce: Uint8Array;
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
type MusigPartialSignature = {
|
|
206
|
+
inputIndex: number;
|
|
207
|
+
participantPubkey: Uint8Array;
|
|
208
|
+
aggregatedPubkey: Uint8Array;
|
|
209
|
+
tapleafHash: Uint8Array;
|
|
210
|
+
partialSignature: Uint8Array;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
type PsbtSignature = PartialSignature | MusigPartialSignature | MusigPubNonce;
|
|
194
214
|
```
|
|
195
215
|
|
|
196
216
|
- `cancel` A function to cancel the action on the Ledger device.
|
|
@@ -220,7 +240,7 @@ const { observable, cancel } = signerBitcoin.signTransaction(
|
|
|
220
240
|
|
|
221
241
|
class DefaultWallet {
|
|
222
242
|
constructor(
|
|
223
|
-
// Derivation path without master key
|
|
243
|
+
// Derivation path without master key representation.
|
|
224
244
|
// Format example: /44'/0'/0'
|
|
225
245
|
public derivationPath: string,
|
|
226
246
|
public template: DefaultDescriptorTemplate,
|
|
@@ -239,23 +259,71 @@ const { observable, cancel } = signerBitcoin.signTransaction(
|
|
|
239
259
|
|
|
240
260
|
- `psbt`
|
|
241
261
|
- **Required**
|
|
242
|
-
- **Type:** `string`
|
|
243
|
-
-
|
|
262
|
+
- **Type:** `string | Psbt`
|
|
263
|
+
- A base64/hex psbt string or [bitcoin-js Psbt](https://github.com/bitcoinjs/bitcoinjs-lib/blob/151173f05e26a9af7c98d8d1e3f90e97185955f1/ts_src/psbt.ts#L131)
|
|
244
264
|
|
|
245
265
|
#### **Returns**
|
|
246
266
|
|
|
247
|
-
- `observable` Emits DeviceActionState updates, including the following details
|
|
267
|
+
- `observable` Emits DeviceActionState updates, including the following details:
|
|
248
268
|
|
|
249
269
|
```typescript
|
|
250
|
-
type
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
270
|
+
type TransactionHash = `0x${string}`;
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
- `cancel` A function to cancel the action on the Ledger device.
|
|
274
|
+
|
|
275
|
+
### Use Case 5: Get wallet address
|
|
276
|
+
|
|
277
|
+
This method allows users to get the wallet address linked to a Ledger device.
|
|
278
|
+
|
|
279
|
+
```typescript
|
|
280
|
+
const { observable, cancel } = signerBitcoin.getWalletAddress(
|
|
281
|
+
derivationPath,
|
|
282
|
+
addressIndex,
|
|
283
|
+
options,
|
|
284
|
+
);
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
#### **Parameters**
|
|
288
|
+
|
|
289
|
+
- `derivationPath`
|
|
290
|
+
|
|
291
|
+
- **Required**
|
|
292
|
+
- **Type:** `string` (e.g. `"84'/0'/0'"` for a Native SegWit wallet)
|
|
293
|
+
- The derivation path used for the Bitcoin address. See [here](https://www.ledger.com/blog/understanding-crypto-addresses-and-derivation-paths) for more information.
|
|
294
|
+
|
|
295
|
+
- `addressIndex`
|
|
296
|
+
|
|
297
|
+
- **Required**
|
|
298
|
+
- **Type:** `number`
|
|
299
|
+
- The desired address index on the Ledger device.
|
|
300
|
+
|
|
301
|
+
- `options`
|
|
302
|
+
|
|
303
|
+
- Optional
|
|
304
|
+
- Type: `WalletAddressOptions`
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
type WalletAddressOptions = {
|
|
308
|
+
checkOnDevice?: boolean;
|
|
309
|
+
change?: boolean;
|
|
310
|
+
};
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
#### **Returns**
|
|
314
|
+
|
|
315
|
+
- `observable` Emits DeviceActionState updates, including the following details:
|
|
316
|
+
|
|
317
|
+
```typescript
|
|
318
|
+
type WalletAddress = {
|
|
319
|
+
address: string;
|
|
254
320
|
};
|
|
255
321
|
```
|
|
256
322
|
|
|
257
323
|
- `cancel` A function to cancel the action on the Ledger device.
|
|
258
324
|
|
|
325
|
+
---
|
|
326
|
+
|
|
259
327
|
## 🔹 Observable Behavior
|
|
260
328
|
|
|
261
329
|
Each method returns an [Observable](https://rxjs.dev/guide/observable) emitting updates structured as [`DeviceActionState`](https://github.com/LedgerHQ/device-sdk-ts/blob/develop/packages/device-management-kit/src/api/device-action/model/DeviceActionState.ts). These updates reflect the operation’s progress and status:
|
|
@@ -299,8 +367,8 @@ observable.subscribe({
|
|
|
299
367
|
}
|
|
300
368
|
case DeviceActionStatus.Error: {
|
|
301
369
|
const { error } = state;
|
|
302
|
-
// Access the error here if
|
|
303
|
-
console.log("An error
|
|
370
|
+
// Access the error here if occurred
|
|
371
|
+
console.log("An error occurred during the action: ", error);
|
|
304
372
|
break;
|
|
305
373
|
}
|
|
306
374
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/device-signer-kit-bitcoin",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-webhid-20250124103640",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"types": "lib/cjs/index.d.ts",
|
|
@@ -33,17 +33,17 @@
|
|
|
33
33
|
"bitcoinjs-lib": "^6.1.6",
|
|
34
34
|
"rxjs": "^7.8.1",
|
|
35
35
|
"ts-node": "^10.9.2",
|
|
36
|
-
"@ledgerhq/device-management-kit": "0.0.0-
|
|
37
|
-
"@ledgerhq/esbuild-tools": "0.0.2",
|
|
36
|
+
"@ledgerhq/device-management-kit": "0.0.0-webhid-20250124103640",
|
|
38
37
|
"@ledgerhq/eslint-config-dsdk": "0.0.2",
|
|
39
38
|
"@ledgerhq/jest-config-dsdk": "1.0.1",
|
|
40
39
|
"@ledgerhq/prettier-config-dsdk": "0.0.2",
|
|
41
|
-
"@ledgerhq/signer-utils": "
|
|
40
|
+
"@ledgerhq/signer-utils": "1.0.2",
|
|
41
|
+
"@ledgerhq/esbuild-tools": "0.0.2",
|
|
42
42
|
"@ledgerhq/tsconfig-dsdk": "1.0.1"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"bitcoinjs-lib": "^6.1.6",
|
|
46
|
-
"@ledgerhq/device-management-kit": "0.0.0-
|
|
46
|
+
"@ledgerhq/device-management-kit": "0.0.0-webhid-20250124103640"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"prebuild": "rimraf lib",
|