Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ledger Live new API updates #780

Merged
merged 45 commits into from
Oct 31, 2024
Merged

Conversation

r-czajkowski
Copy link
Contributor

@r-czajkowski r-czajkowski commented Oct 24, 2024

This PR moves the implementation of the Ledger Live Bitcoin provider and connector from Orangekit to the Acre dapp. We decided to keep this implementation on the Acre side because there are many implementation details specified for Acre. Here we also use new functions from the new Ledger Live Wallet API.

Add `signWithdrawMessage` function to support the clear signing with
Ledger Live. This function is optional so if the bitcoin provider
supports the clear signing it should implement this method and this
function will be used in the withdrawal flow.
We need to use the custom Acre module to support the clear signing.
We use new methods from the Ledger Live Wallet API and we need to set
them in manifest file.
Adjust the Acre SDK to the new orangekit API.
We can sign the message with correct derivation path in Ledger Live.
@r-czajkowski r-czajkowski added 🎨 dapp dApp 🔌 sdk TypeScript SDK Library labels Oct 24, 2024
Copy link

netlify bot commented Oct 24, 2024

Deploy Preview for acre-dapp-testnet ready!

Name Link
🔨 Latest commit 5de537c
🔍 Latest deploy log https://app.netlify.com/sites/acre-dapp-testnet/deploys/6723a6656150500008178113
😎 Deploy Preview https://deploy-preview-780--acre-dapp-testnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Expose the `BitcoinAddressHelper` function from the Orangekit package.
We need this function in the dapp.
We want to port the Ledger Live Bitcoin provider implementation from
orangekit to Acre as it contains many details specific to the Acre dapp
only.
Move the Ledger Live connector and bitcoin provider implementation from
the orangekit package to the dapp. Since there are many implementation
details specified for Acre dapp, we decided to keep this implementation
on Acre side.
We use `transactionSignAndBroadcast` function from the Acre custom
module.
Make the `normalizeV` method private.
We can use `BitcoinNetwork` enum defined in Acre SDK.
We check above if the `this.#account` is undefined.
Pass correct network param to `AcreLedgerLiveBitcoinProvider`
constructor.
Set the `readonly` variables at the beginning.
Extract the sign message shared code to a separate function.
Test function with supported and unsupported addresse types.
Display correct method name for test.
Let's extract this derivation path to a constant and use it in
functions. We want to always operate on the zero address.
Adjust the code to the new Orangekit API.
Add the `bignumber.js` lib used by the Ledger Live packages. When
ignoring the TS error we're losing the advantage of the type safety TS
provides. We assume that the external library performs the conversion,
but if the implementation in the Ledger library changes, we will only
find out at runtime. Here we pass the satoshi value as a BigNumber
object to the Ledger Live module.
dapp/src/utils/orangekit/ledger-live/bitcoin-provider.ts Outdated Show resolved Hide resolved
dapp/src/utils/orangekit/ledger-live/bitcoin-provider.ts Outdated Show resolved Hide resolved
sdk/src/lib/bitcoin/providers/provider.ts Outdated Show resolved Hide resolved
sdk/src/lib/redeemer-proxy.ts Outdated Show resolved Hide resolved
sdk/test/lib/redeemer-proxy.test.ts Outdated Show resolved Hide resolved
sdk/test/utils/mock-orangekit.ts Outdated Show resolved Hide resolved
The `satoshis` param is a `number` and there is no need to convert it to
string when createing the `BigNumber` object.
Update `signMessage` and `signWithdrawMessage` docs. These functions
return signature not hash of the signed message.
We can import SafeTransactionData from `./bitcoin` instead of
`@orangekit/sdk`.
Use the defined type `BitcoinSignSafeTransactionMessageFn` from the
`@orangekit/sdk` package.
Cover a case when the bitcoin provider implements `signWithdrawMessage`
and that one that doesn't.
@r-czajkowski r-czajkowski marked this pull request as ready for review October 31, 2024 10:09
@r-czajkowski r-czajkowski marked this pull request as draft October 31, 2024 10:10
@r-czajkowski r-czajkowski marked this pull request as ready for review October 31, 2024 10:10
@@ -29,6 +32,13 @@ export interface BitcoinProvider {

/**
* Signs withdraw message.
* @param message Message to sign.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a comment that this function is optional, and if not implemented, we will fall back to the signMessage function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dapp/src/utils/orangekit/ledger-live/bitcoin-provider.ts Outdated Show resolved Hide resolved
dapp/src/utils/orangekit/ledger-live/bitcoin-provider.ts Outdated Show resolved Hide resolved
dapp/src/utils/orangekit/ledger-live/bitcoin-provider.ts Outdated Show resolved Hide resolved
Mention in the docs that `signWithdrawMessage` function is optional and
if it is not implemented the `signMessage` function will be used to sign
the withdrawal message.
`LedgerLiveWalletApiBitcoinProviderOptions` ->
`AcreLedgerLiveBitcoinProviderOptions` to match the provider name.
We should return the address at `0` index so we need to call the
`getAdress` function from the bitcoin module. The address from the
account object is always a fresh address and may be different from
address at `0` index.
Copy link
Member

@nkuba nkuba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left one non-blocking comment, that can be addressed in another PR..

Comment on lines +38 to +40
* @param data Withdrawal transaction data. @returns A signature for a given
* message, which proves that the owner of the account has agreed to the
* message content.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're missing a line break before @returns.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in be9fa83.

@nkuba nkuba merged commit 5540871 into ledger-live-updates Oct 31, 2024
24 checks passed
@nkuba nkuba deleted the ledger-live-new-api-updates branch October 31, 2024 16:31
nkuba added a commit that referenced this pull request Nov 4, 2024
Depends on: #780 

This PR fixes Ledger Live wallet connection bug. If the user rejects the
login message signing and closes the modal, they should get back to the
initial state of the not-connected account.

Steps to recreate the bug:
1. Open the account connection.
2. Select a supported account.
3. Cancel login message signing and clse the connection modal.
4. The dApp looks like it is connected to an account, but after
switching the account, it shows a "Something went wrong" error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎨 dapp dApp 🔌 sdk TypeScript SDK Library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants