feat: add Ledger hardware wallet support #109
Draft
+980
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds Ledger hardware wallet integration using
@hot-labs/near-connect's custom wallet executor framework, bringing feature parity with the Web4 implementation.Implementation
Executor (
public/ledger-executor.js)LedgerClientclass handles APDU communication (CLA 0x80, 250-byte chunking, derivation path44'/397'/0'/0'/1')Manifest (
lib/ledger-manifest.ts)Registration (
stores/near-store.ts)Browser Support
WebHID API requirement limits support to Chrome/Edge/Opera 89+ on desktop. Gracefully skips registration on unsupported browsers (Firefox, Safari, mobile).
Dependencies
All dependencies loaded from CDN (no build-time imports):
@ledgerhq/hw-transport-webhid@6.29.4@near-js/crypto@1.4.1,@near-js/transactions@1.3.3,@near-js/utils@0.2.2Documentation
docs/ledger-wallet-support.md: Technical architecture, APDU protocol details, security modeldocs/ledger-testing-guide.md: Manual testing procedures for device interactionWarning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
fonts.googleapis.com/usr/local/bin/node node /home/REDACTED/work/treasury26/treasury26/nt-fe/node_modules/.bin/next build --detach --pid-file /run/containerd/io.containerd.runtime.v2.task/moby/f6f3be56cd0a141a7d1ab82482fe9954cdaa44eb43715352d896e1dbc23ee629/f8ab01d2fb65521395bf8935834cc661e78151be5ceb06e3f5ed1b1cbd6b45c9.pid f6f3be56cd0a141a7d1ab82482fe9954cdaa44eb43715352d896e1dbc23ee629(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
Summary
Add Ledger hardware wallet support to the treasury26 app by creating a custom wallet executor for
@hot-labs/near-connect. This brings feature parity with the Web4 page which already supports Ledger via@near-wallet-selector/ledger.Background
@hot-labs/near-connectfor wallet connections@near-wallet-selector/ledger@hot-labs/near-connectsupports custom wallet executors withusbandhidpermissions for hardware walletsImplementation Details
1. Create Ledger Executor Script (
public/ledger-executor.js)Create a self-contained JavaScript file that:
esm.shfor dependencies:@ledgerhq/hw-transport-webhidfor Ledger communication@near-js/crypto,@near-js/transactions,@near-js/utilsfor NEAR transaction handlingLedgerClientclass for APDU communication (ported from@near-wallet-selector/ledger)signIn(params)- Connect Ledger, get public key, prompt for account ID, verify access keysignOut(params)- Disconnect and clear stored accountsgetAccounts(params)- Return stored accountssignAndSendTransaction(params)- Build, sign with Ledger, and broadcast transactionsignAndSendTransactions(params)- Handle multiple transactionssignMessage(params)- NEP-413 message signingwindow.selector.ready(wallet)to register with hot-connectwindow.selector.ui.whenApprove()for user promptsKey Ledger constants:
44'/397'/0'/0'/1'0x2c972. Create Ledger Manifest (
nt-fe/lib/ledger-manifest.ts)3. Register Ledger in NearConnector (
nt-fe/stores/near-store.ts)Modify the store to register the Ledger wallet after the connector initializes:
Technical Notes
Ledger APDU Communication
The executor uses the same APDU protocol as
@near-wallet-selector/ledger:Transaction Signing Flow
@near-js/transactionsAccount Discovery
Since Ledger only provides a public key, the user must enter their account ID. The executor:
view_access_keyRPCReferences
Related Issue
Resolves #89
This pull request was created from Copilot chat.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.