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

feat: add support for ledger live and mew address path in ledger import #1534

Merged
merged 8 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
208 changes: 208 additions & 0 deletions .yarn/versions/804d1238.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
releases:
"@fluent-wallet/account": patch
"@fluent-wallet/addr-by-network": patch
"@fluent-wallet/base32-address": patch
"@fluent-wallet/cfx_accounts": patch
"@fluent-wallet/cfx_call": patch
"@fluent-wallet/cfx_chain-id": patch
"@fluent-wallet/cfx_check-balance-against-transaction": patch
"@fluent-wallet/cfx_client-version": patch
"@fluent-wallet/cfx_epoch-number": patch
"@fluent-wallet/cfx_estimate-1559-fee": patch
"@fluent-wallet/cfx_estimate-gas-and-collateral": patch
"@fluent-wallet/cfx_fee-history": patch
"@fluent-wallet/cfx_gas-price": patch
"@fluent-wallet/cfx_get-account": patch
"@fluent-wallet/cfx_get-account-pending-info": patch
"@fluent-wallet/cfx_get-account-pending-transactions": patch
"@fluent-wallet/cfx_get-accumulate-interest-rate": patch
"@fluent-wallet/cfx_get-admin": patch
"@fluent-wallet/cfx_get-balance": patch
"@fluent-wallet/cfx_get-best-block-hash": patch
"@fluent-wallet/cfx_get-block-by-block-number": patch
"@fluent-wallet/cfx_get-block-by-epoch-number": patch
"@fluent-wallet/cfx_get-block-by-hash": patch
"@fluent-wallet/cfx_get-block-by-hash-with-pivot-assumption": patch
"@fluent-wallet/cfx_get-block-reward-info": patch
"@fluent-wallet/cfx_get-blocks-by-epoch": patch
"@fluent-wallet/cfx_get-code": patch
"@fluent-wallet/cfx_get-collateral-for-storage": patch
"@fluent-wallet/cfx_get-confirmation-risk-by-hash": patch
"@fluent-wallet/cfx_get-deposit-list": patch
"@fluent-wallet/cfx_get-fee-burnt": patch
"@fluent-wallet/cfx_get-interest-rate": patch
"@fluent-wallet/cfx_get-logs": patch
"@fluent-wallet/cfx_get-max-gas-limit": patch
"@fluent-wallet/cfx_get-next-nonce": patch
"@fluent-wallet/cfx_get-next-usable-nonce": patch
"@fluent-wallet/cfx_get-pos-economics": patch
"@fluent-wallet/cfx_get-pos-reward-by-epoch": patch
"@fluent-wallet/cfx_get-skipped-blocks-by-epoch": patch
"@fluent-wallet/cfx_get-sponsor-info": patch
"@fluent-wallet/cfx_get-staking-balance": patch
"@fluent-wallet/cfx_get-status": patch
"@fluent-wallet/cfx_get-storage-at": patch
"@fluent-wallet/cfx_get-storage-root": patch
"@fluent-wallet/cfx_get-supply-info": patch
"@fluent-wallet/cfx_get-transaction-by-hash": patch
"@fluent-wallet/cfx_get-transaction-receipt": patch
"@fluent-wallet/cfx_get-vote-list": patch
"@fluent-wallet/cfx_max-priority-fee-per-gas": patch
"@fluent-wallet/cfx_net-version": patch
"@fluent-wallet/cfx_opened-method-groups": patch
"@fluent-wallet/cfx_request-accounts": patch
"@fluent-wallet/cfx_send-raw-transaction": patch
"@fluent-wallet/cfx_send-transaction": patch
"@fluent-wallet/cfx_sign-transaction": patch
"@fluent-wallet/cfx_sign-tx-with-ledger-nano-s": patch
"@fluent-wallet/cfx_sign-typed-data_v4": patch
"@fluent-wallet/component-menu": minor
"@fluent-wallet/consts": patch
"@fluent-wallet/contract-method-name": patch
"@fluent-wallet/db": patch
"@fluent-wallet/detect-address-type": patch
"@fluent-wallet/did": patch
"@fluent-wallet/estimate-tx": patch
"@fluent-wallet/eth_accounts": patch
"@fluent-wallet/eth_block-number": patch
"@fluent-wallet/eth_call": patch
"@fluent-wallet/eth_chain-id": patch
"@fluent-wallet/eth_estimate-1559-fee": patch
"@fluent-wallet/eth_estimate-gas": patch
"@fluent-wallet/eth_fee-history": patch
"@fluent-wallet/eth_gas-price": patch
"@fluent-wallet/eth_get-balance": patch
"@fluent-wallet/eth_get-block-by-hash": patch
"@fluent-wallet/eth_get-block-by-number": patch
"@fluent-wallet/eth_get-code": patch
"@fluent-wallet/eth_get-logs": patch
"@fluent-wallet/eth_get-transaction-by-hash": patch
"@fluent-wallet/eth_get-transaction-count": patch
"@fluent-wallet/eth_get-transaction-receipt": patch
"@fluent-wallet/eth_max-priority-fee-per-gas": patch
"@fluent-wallet/eth_request-accounts": patch
"@fluent-wallet/eth_send-raw-transaction": patch
"@fluent-wallet/eth_send-transaction": patch
"@fluent-wallet/eth_sign-transaction": patch
"@fluent-wallet/eth_sign-tx-with-ledger-nano-s": patch
"@fluent-wallet/eth_sign-typed-data_v4": patch
"@fluent-wallet/ledger": patch
"@fluent-wallet/net_version": patch
"@fluent-wallet/personal_sign": patch
"@fluent-wallet/rpc-engine": patch
"@fluent-wallet/shorten-address": patch
"@fluent-wallet/signature": patch
"@fluent-wallet/single-call-balance-tracker": patch
"@fluent-wallet/spec": patch
"@fluent-wallet/tx-history-checker": patch
"@fluent-wallet/txpool_next-nonce": patch
"@fluent-wallet/wallet_accounts": patch
"@fluent-wallet/wallet_add-conflux-chain": patch
"@fluent-wallet/wallet_add-ethereum-chain": patch
"@fluent-wallet/wallet_add-hd-path": patch
"@fluent-wallet/wallet_add-network": patch
"@fluent-wallet/wallet_add-pending-user-auth-request": patch
"@fluent-wallet/wallet_add-vault": patch
"@fluent-wallet/wallet_after-unlock": patch
"@fluent-wallet/wallet_chain-id": patch
"@fluent-wallet/wallet_cleanup-tx": patch
"@fluent-wallet/wallet_create-account": patch
"@fluent-wallet/wallet_create-address": patch
"@fluent-wallet/wallet_db-query": patch
"@fluent-wallet/wallet_delete-account": patch
"@fluent-wallet/wallet_delete-account-group": patch
"@fluent-wallet/wallet_delete-app": patch
"@fluent-wallet/wallet_delete-memo": patch
"@fluent-wallet/wallet_delete-network": patch
"@fluent-wallet/wallet_detect-address-type": patch
"@fluent-wallet/wallet_detect-network-type": patch
"@fluent-wallet/wallet_discover-accounts": patch
"@fluent-wallet/wallet_enrich-conflux-tx": patch
"@fluent-wallet/wallet_enrich-ethereum-tx": patch
"@fluent-wallet/wallet_enrich-txs": patch
"@fluent-wallet/wallet_export-account": patch
"@fluent-wallet/wallet_export-account-group": patch
"@fluent-wallet/wallet_export-all": patch
"@fluent-wallet/wallet_generate-address": patch
"@fluent-wallet/wallet_generate-private-key": patch
"@fluent-wallet/wallet_get-account-address-by-network": patch
"@fluent-wallet/wallet_get-account-group": patch
"@fluent-wallet/wallet_get-account-group-vault-value": patch
"@fluent-wallet/wallet_get-address-private-key": patch
"@fluent-wallet/wallet_get-balance": patch
"@fluent-wallet/wallet_get-block-or-epoch-number": patch
"@fluent-wallet/wallet_get-block-time": patch
"@fluent-wallet/wallet_get-blockchain-explorer-url": patch
"@fluent-wallet/wallet_get-current-account": patch
"@fluent-wallet/wallet_get-current-network": patch
"@fluent-wallet/wallet_get-current-viewing-app": patch
"@fluent-wallet/wallet_get-fluent-metadata": patch
"@fluent-wallet/wallet_get-import-hardware-wallet-info": patch
"@fluent-wallet/wallet_get-network": patch
"@fluent-wallet/wallet_get-next-nonce": patch
"@fluent-wallet/wallet_get-next-usable-nonce": patch
"@fluent-wallet/wallet_get-pending-auth-request": patch
"@fluent-wallet/wallet_get-permissions": patch
"@fluent-wallet/wallet_get-preferences": patch
"@fluent-wallet/wallet_get-side-panel-enabled": patch
"@fluent-wallet/wallet_get-side-panel-supported": patch
"@fluent-wallet/wallet_handle-unfinished-cfx-tx": patch
"@fluent-wallet/wallet_handle-unfinished-eth-tx": patch
"@fluent-wallet/wallet_handle-unfinished-txs": patch
"@fluent-wallet/wallet_import-address": patch
"@fluent-wallet/wallet_import-all": patch
"@fluent-wallet/wallet_import-hardware-wallet-account-group-or-account": patch
"@fluent-wallet/wallet_import-mnemonic": patch
"@fluent-wallet/wallet_import-private-key": patch
"@fluent-wallet/wallet_metadata-for-popup": patch
"@fluent-wallet/wallet_network1559compatible": patch
"@fluent-wallet/wallet_refetch-balance": patch
"@fluent-wallet/wallet_refetch-token-list": patch
"@fluent-wallet/wallet_refetch-tx-list": patch
"@fluent-wallet/wallet_register-site-metadata": patch
"@fluent-wallet/wallet_request-accounts": patch
"@fluent-wallet/wallet_request-permissions": patch
"@fluent-wallet/wallet_request-unlock-ui": patch
"@fluent-wallet/wallet_send-transaction": patch
"@fluent-wallet/wallet_send-transaction-with-action": patch
"@fluent-wallet/wallet_set-app-current-account": patch
"@fluent-wallet/wallet_set-app-current-network": patch
"@fluent-wallet/wallet_set-current-account": patch
"@fluent-wallet/wallet_set-current-network": patch
"@fluent-wallet/wallet_set-preferences": patch
"@fluent-wallet/wallet_set-side-panel-enabled": patch
"@fluent-wallet/wallet_switch-conflux-chain": patch
"@fluent-wallet/wallet_switch-ethereum-chain": patch
"@fluent-wallet/wallet_unlock": patch
"@fluent-wallet/wallet_unwatch-asset": patch
"@fluent-wallet/wallet_update-account": patch
"@fluent-wallet/wallet_update-account-group": patch
"@fluent-wallet/wallet_update-network": patch
"@fluent-wallet/wallet_update-token-list": patch
"@fluent-wallet/wallet_upsert-memo": patch
"@fluent-wallet/wallet_user-approved-auth-request": patch
"@fluent-wallet/wallet_user-rejected-auth-request": patch
"@fluent-wallet/wallet_validate-app-permissions": patch
"@fluent-wallet/wallet_validate-mnemonic": patch
"@fluent-wallet/wallet_validate-password": patch
"@fluent-wallet/wallet_validate-private-key": patch
"@fluent-wallet/wallet_validate20token": patch
"@fluent-wallet/wallet_watch-asset": patch
"@fluent-wallet/wallet_zero-account-group": patch
browser-extension: patch
helios: patch
helios-background: patch
helios-popup: patch
workspace-tools: patch

declined:
- "@fluent-wallet/component-alert"
- "@fluent-wallet/component-button"
- "@fluent-wallet/component-checkbox"
- "@fluent-wallet/component-input"
- "@fluent-wallet/component-link"
- "@fluent-wallet/component-loading"
- "@fluent-wallet/component-modal"
- "@fluent-wallet/component-tag"
- "@fluent-wallet/component-toast"
- doc
5 changes: 5 additions & 0 deletions packages/consts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ export const ETH_SEPOLIA_EXPLORER_URL = 'https://sepolia.etherscan.io'
export const DEFAULT_CFX_HDPATH = `m/44'/503'/0'/0`
export const DEFAULT_ETH_HDPATH = `m/44'/60'/0'/0`

// for ledger import address path
export const LEDGER_LIVE_PATH = `m/44'/60'/0'/0/0`
// for MEW or MyCrypto import address path
export const MEW_PATH = `m/44'/60'/0'`

export const REGENERATE = 'REGENERATE'

export const CFX_LOCALNET_RPC_ENDPOINT = 'http://localhost:12537'
Expand Down
2 changes: 1 addition & 1 deletion packages/ledger/conflux.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export default class Conflux {
const addressArr = []
try {
for (const index of indexArray) {
const hdPath = `${HDPATH.CONFLUX}${index}`
const hdPath = `${HDPATH.CONFLUX}/${index}`
const {address} = await this.getAddress(hdPath)
const {hexAddress} = decode(address)
addressArr.push({
Expand Down
5 changes: 3 additions & 2 deletions packages/ledger/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ export const INS = {
OPEN_APP: 0xd8,
}
export const HDPATH = {
CONFLUX: "44'/503'/0'/0/",
ETHEREUM: "44'/60'/0'/0/",
CONFLUX: "44'/503'/0'/0",
ETHEREUM: "44'/60'/0'/0",
LEDGER_LIVE: "44'/60'/0'/0/0",
}

export const ERROR = {
Expand Down
20 changes: 15 additions & 5 deletions packages/ledger/ethereum.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,14 @@ export default class Ethereum {
}
}

async getAddressList(indexArray) {
async getAddressList(indexArray, path = HDPATH.ETHEREUM) {
if (!Array.isArray(indexArray)) return []
const isNumber = indexArray.every(function (item) {
return typeof item === 'number'
})
const isNumber = indexArray.every(item => typeof item === 'number')
if (!isNumber) return []
const addressArr = []
try {
for (const index of indexArray) {
const hdPath = `${HDPATH.ETHEREUM}${index}`
const hdPath = this.getAddressesPathForIndex(index, path)
const {address} = await this.getAddress(hdPath)
addressArr.push({
address,
Expand Down Expand Up @@ -224,4 +222,16 @@ export default class Ethereum {
}
return error
}
getAddressesPathForIndex = (index, inputPath) => {
// if the path starts with 'm/', remove it
// because the ledger app doesn't need the 'm/' prefix(see: https://github.com/LedgerHQ/ledger-live/blob/develop/libs/ledger-live-common/src/families/celo/hw-app-celo.ts#L150)
const path = inputPath.startsWith('m/')
? inputPath.replace('m/', '')
: inputPath

if (path === HDPATH.LEDGER_LIVE) {
return `44'/60'/${index}'/0/0`
}
return `${path}/${index}`
}
}
Loading
Loading