HOLIDAY OFFER: Get the gift of up to $70 of Bitcoin. While supplies last!

Shop now

Tech | 11/13/2024

How we used Ledger Key Ring Protocol in Ledger Live

Most of the applications you are using in your daily life come up with a login mechanism – typically a username/password pair – which allows you to authenticate and ensure you and only you can retrieve your personal information from online services. However, this information is stored in their databases, which means it is accessible to a few administrators, who can then access your data, even without knowing your credentials.

If you use Ledger Live, you probably noticed there is no such mechanism and still when you open the app, you find back all your personal data (accounts, preferences and settings, ..). This is only possible because the user’s data is persisted locally and not online. At Ledger we chose this approach because we care about privacy. No one should have access to your personal information, not even us.

Here’s the downside though: If a user has both Ledger Live Mobile and Ledger Live Desktop, there is no way to keep her personal data in sync between these 2 instances. To add, rename or edit an account, you need to do it both on mobile and on desktop.  Not a pleasant experience!

Preserving privacy whilst sharing data online

To solve this problem, we needed a way to share data between Live instances in a secure and private way:

  • Allow authentication without being able to identify actual users
  • Only store online data that has been previously encrypted on the client side
  • Ensure encryption key can be shared/unshared to a selected set of Ledger Live instances

This was made possible by a protocol we created: “Ledger Key Ring Protocol”, which allows sharing secrets between a group of members.

Members, not users! As stated in the whitepaper, “the user “connects” its application to a service by authenticating with the secure device in an anonymous way and chooses which encryption keys to share to the application.

Members who have access to the encryption key are Ledger Live applications. Authentication relies on a Ledger device. Who is the user behind the application and the device? We don’t need to know, we don’t want to know.

Ledger Key Ring in Ledger Live

The first use case of the Ledger Key Ring protocol in Ledger Live is the Ledger Sync feature that allows our users to sync their accounts between different Ledger Live instances they may use.

Let’s deep dive into how the Ledger Key Ring protocol was specifically implemented into Ledger Live to serve as Ledger Sync’s backbone.

Important point worth mentioning: This feature will only work upon activation. As a user, none of your data will be encrypted and stored online if you don’t enable it. If you were to change your mind later, you can deactivate it and all the encrypted data will be deleted right away from online services.

Many tech components involved

As explained in the whitepaper, the Ledger Key Ring relies on a tree data structure which stores encryption keys as well as members who have access to them. It can handle many application domains. Ledger Sync is one of these applications.

Its creation, evolution and deletion are handled by many different tech components with well defined responsibilities:

  • Ledger Sync app that runs on a Ledger device (Nano S+, Nano X, Stax and Flex) and allows to create a Key Ring and generate all secrets
  • hw-ledger-key-ring-protocol library that
    • Handles communication with the device app through APDU
    • Implements the Ledger Key Ring  protocol to create encryption key and share them with trusted members
  • Ledger Key Ring backend that handles authentication and provides a CRUD like API to fetch, modify and delete Key Rings 
  • Ledger Key Ring SDK that is responsible for orchestrating calls to the backend and the device app, performing checks and crafting Key Ring nodes using hw-ledger-key-ring-protocol abstractions.

User Journey

Let’s follow a user typical journey that would like to synchronize accounts on Ledger Live on Desktop and Ledger Live mobile applications.

Initiating a Ledger Key Ring with Ledger Live Desktop

The activation flow can be found in Settings > General > Ledger Sync > Manage

As soon as the user expresses interest in using the feature by clicking on the “Sync your accounts” button, a key pair is generated over SECP256K1: it will act as member credentials for the Ledger Live application in use.

Then, if not already there, the Ledger Sync device app is installed automatically and the user gets prompted to open it.

From there, two more steps need to be performed:

Step 1 – Log in

First, the user needs to ”log in”. In other words, the ledger device will be used to authenticate by signing a challenge sent by the Ledger Key Ring API. Both signature and challenge are sent to the backend which verifies it is correct and not tampered and returns an access token in exchange. 

Ledger Live will put in use its access token right away by requesting the list of all Key Rings associated with it. Of course, as the process is being initiated, the answer is an empty object.

Step 2 – Enable Ledger Sync 

Since no Key Ring exists yet, enabling Ledger Sync translates here into:

  • Initiating the Key Ring by creating a main secret. This secret can only be read by the device and is used to generate encryption keys used by Ledger Live to protect user data.
  • Deriving an encryption key from the main secret for this specific application.
  • Adding the Ledger Live instance as a member.
  • Sending the newly created Key Ring to the Ledger Key Ring backend to persist it.

Ledger Live instance has now access to the Key Ring id and applicationPath as well as the encryption key that will be used by the Ledger Sync feature to encrypt and decrypt data.

From now on, this Ledger Live Desktop instance can authenticate with its own credentials, as long as they are valid, without the need of the device.

Adding a second member: Ledger Live Mobile

The metadata of Ledger Live Desktop user accounts are now encrypted and stored online securely.

Let’s add a second Ledger Live instance, a mobile version, to be able to synchronize the data between the two.

In Ledger Live Mobile, let’s pick “Use your Ledger to enable Ledger Sync”.


Important to know, you need to use either the same device or a device seeded with the same recovery phrase.


The user will go through  the same two steps on the Ledger Device but what happens under the hood varies a bit when enabling the feature, as here, we’re joining an existing Key Ring and its full applicationPath: they are directly retrieved from the backend.

So here, enabling Ledger Sync translates into:

  • Adding the Ledger Live instance member to the Key Ring
  • Sending the modification to Ledger Key Ring backend

The two Ledger Live applications, mobile and desktop, have both enabled Ledger Sync and accounts data will be synchronized between the two instances.

Removing a member

Let’s say now that you also added a third Ledger Live instance to your Key Ring and you would like to remove it while still being able to keep in sync the other two.

Actually, just removing the member from an “allow list” or deleting the encryption key from its storage is not sufficient. Similarly to what you would do if you shared your home key with someone who can’t be trusted anymore: no other choice than installing a new lock and redistributing new keys to people you still want to let in.

We will:

  • Create a new derivation “m/0’/16’/1’” that will come with a new encryption key and make the former one obsolete.
  • Add back members to this node, except for the member we want to “remove”.
  • Reencrypt the data with the new key.

This is called rotating the encryption keys.

Deactivating Ledger Sync and deleting the Key Ring

The user is free to stop using LedgerSync at any time, even without having access to the device that was used to create the Key Ring.

Clicking this button and confirming the action will:

  • Trigger a call to the API to delete the Key Ring from servers.
  • Also request deletion of encrypted data from Ledger Sync backend.
  • Erase local data related to the Key Ring, member Credentials and access token.

Later in time, when other Ledger Live instances try to access Ledger Sync, they will receive an error from the backend that will result in them also deleting their Key Ring local data.

Conclusion

By building Ledger Sync using the Ledger Key Ring protocol, we are now able to keep multiple Live applications in sync whilst preserving users’ privacy. A standard web2 feature done the web3 way: convenience without sacrificing privacy.

This is the first step in a series of new opportunities, stay tuned for more.


Alexandrine BOISSIERE
Head of Engineering – Wallet Experience

Stay in touch

Announcements can be found in our blog. Press contact:
[email protected]

Subscribe to our
newsletter

New coins supported, blog updates and exclusive offers directly in your inbox


Your email address will only be used to send you our newsletter, as well as updates and offers. You can unsubscribe at any time using the link included in the newsletter.

Learn more about how we manage your data and your rights.