Skip to content
This repository has been archived by the owner on Jun 27, 2022. It is now read-only.

Split hw-app-btc, refactor in async/await, progress events #437

Merged
merged 1 commit into from Jan 4, 2020

Conversation

gre
Copy link
Contributor

@gre gre commented Jan 4, 2020

the monolithic code of Btc.js has been

  • split into many files
  • refactored in async/await

What this PR didn't do:

  • the logic itself could probably be simplified, but this PR simply ported the code.

createPaymentTransactionNew and signP2SHTransaction

There is also a signature change for the methods createPaymentTransactionNew and signP2SHTransaction: basically instead of taking many arguments, it's now one object with named fields:

The previous signature is still supported, but a console.warn deprecated message will appear. Support will be dropped in next major bump.

-btc.createPaymentTransactionNew(
-[ [tx1, 1] ],
-["0'/0/0"],
-undefined,
-"01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
-).then(res => ...);
+btc.createTransaction({
+inputs: [ [tx1, 1] ],
+associatedKeysets: ["0'/0/0"],
+outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
+}).then(res => ...);
-btc.signP2SHTransaction(
-[ [tx, 1, "52210289b4a3ad52a919abd2bdd6920d8a6879b1e788c38aa76f0440a6f32a9f1996d02103a3393b1439d1693b063482c04bd40142db97bdf139eedd1b51ffb7070a37eac321030b9a409a1e476b0d5d17b8
04fcdb81cf30f9b99c6f3ae1178206e08bc500639853ae"] ],
-["0'/0/0"],
-"01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
-).then(result => ...);
+btc.signP2SHTransaction({
+inputs: [ [tx, 1, "52210289b4a3ad52a919abd2bdd6920d8a6879b1e788c38aa76f0440a6f32a9f1996d02103a3393b1439d1693b063482c04bd40142db97bdf139eedd1b51ffb7070a37eac321030b9a409a1e476b0d5d17b804fcdb81cf30f9b99c6f3ae1178206e08bc500639853ae"] ],
+associatedKeysets: ["0'/0/0"],
+outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
+}).then(result => ...);

createPaymentTransactionNew onDevice* callbacks

Signing a BTC transaction can take time so we have introduced some callback to track the events:

  onDeviceStreaming?: number => void,
  onDeviceSignatureRequested?: () => void,
  onDeviceSignatureGranted?: () => void

This allows to track the progress events when the utxo are streaming to the device before and after the signature, and also to know when the signature is effectively displayed on the device.

In Ledger Live codebase, we aim to have a uniform interface for this and we might later refactor our hw-app-* libraries to have a same interface too.

Capture d’écran 2020-01-04 à 16 30 48

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant