Skip to content

fix: allow users to use different apps than celo or ethereum #544

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

Merged
merged 3 commits into from
Mar 14, 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
5 changes: 5 additions & 0 deletions .changeset/sharp-fishes-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@celo/wallet-ledger': patch
---

Allow users to use other apps than ethereum or celo, namely "eth recovery" in order to recovery funds or signTypedData which isnt supported by celo but would require the correct derivationPath
5 changes: 5 additions & 0 deletions .changeset/yellow-mails-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@celo/viem-account-ledger': patch
---

Allow users to use other apps than ethereum or celo, namely eth recovery in order to recovery funds or signTypedData which isnt supported by celo but would require the correct derivationPath (which, in turn, isn't supported by ethereum)
42 changes: 41 additions & 1 deletion packages/sdk/wallets/wallet-ledger/src/ledger-wallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import TransportNodeHid from '@ledgerhq/hw-transport-node-hid'
import Web3 from 'web3'
import { meetsVersionRequirements } from './ledger-utils'
import { AddressValidation, LedgerWallet } from './ledger-wallet'
import { AddressValidation, CELO_BASE_DERIVATION_PATH, LedgerWallet } from './ledger-wallet'
import {
ACCOUNT_ADDRESS1,
ACCOUNT_ADDRESS2,
Expand Down Expand Up @@ -226,6 +226,46 @@ describe('LedgerWallet class', () => {
`)
expect(wallet.ledger!.getAddress).toHaveBeenCalledTimes(6)
})
describe('with other ledger apps', () => {
describe('with the ethereum-recovery app', () => {
beforeEach(() => {
wallet = new LedgerWallet({}, [0], CELO_BASE_DERIVATION_PATH, [1, 2])
mockLedger(wallet, mockForceValidation, { name: 'ethereum-recovery' })
})
it('shows warning on initialization but still initalizes', async () => {
const logMock = jest.spyOn(console, 'error')
await wallet.init()
expect(logMock.mock.calls).toMatchInlineSnapshot(`
[
[
"
---
Beware, you opened the ethereum-recovery app instead of the Celo app. We cannot ensure the safety of using this SDK with ethereum-recovery. USE AT YOUR OWN RISK.
---
",
],
]
`)
})
})
describe('with the ethereum app', () => {
beforeEach(() => {
wallet = new LedgerWallet({}, [0, 1, 2, 3], ETHEREUM_DERIVATION_PATH, [6, 7, 8])
mockLedger(wallet, mockForceValidation, { name: 'ethereum' })
})
it('shows warning on initialization but still initalizes', async () => {
const warnMock = jest.spyOn(console, 'warn')
await wallet.init()
expect(warnMock.mock.calls).toMatchInlineSnapshot(`
[
[
"Beware, you opened the Ethereum app instead of the Celo app. Some features may not work correctly, including token transfers.",
],
]
`)
})
})
})
})

describe('after initializing', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/wallets/wallet-ledger/src/ledger-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ export class LedgerWallet extends RemoteWallet<LedgerSigner> implements ReadOnly
`Beware, you opened the Ethereum app instead of the Celo app. Some features may not work correctly, including token transfers.`
)
} else {
throw new Error(
`Beware, you opened the ${appName} app instead of the Celo app. We cannot ensure the safety of using this SDK with ${appName}.`
console.error(
`\n---\nBeware, you opened the ${appName} app instead of the Celo app. We cannot ensure the safety of using this SDK with ${appName}. USE AT YOUR OWN RISK.\n---\n`
)
}
if (!appConfiguration.arbitraryDataEnabled) {
Expand Down
18 changes: 13 additions & 5 deletions packages/viem-account-ledger/src/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ describe('utils', () => {
})

describe('assertCompat', () => {
it("throws if it doesn't meet the requirements", async () => {
await expect(assertCompat(mockLedger({ version: '1.0.0' }))).rejects.toMatchInlineSnapshot(
`[Error: Due to technical issues, we require the users to update their ledger celo-app to >= 1.2.0. You can do this on ledger-live by updating the celo-app in the app catalog.]`
)
})
it('warns if it doesnt enable `arbitraryDataEnabled`', async () => {
const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined)
await expect(assertCompat(mockLedger({ arbitraryDataEnabled: 0 }))).resolves.toBeTruthy()
Expand All @@ -89,6 +84,19 @@ describe('utils', () => {
]
`)
})
it('warns if it using with unknown apps', async () => {
const error = vi.spyOn(console, 'error').mockImplementation(() => undefined)
await expect(assertCompat(mockLedger({ name: 'unknown' }))).resolves.toBeTruthy()
expect(error.mock.lastCall).toMatchInlineSnapshot(`
[
"
---
Beware, you opened the unknown app instead of the Celo app. We cannot ensure the safety of using this SDK with unknown. USE AT YOUR OWN RISK.
---
",
]
`)
})
it('works', async () => {
await expect(assertCompat(mockLedger())).resolves.toBeTruthy()
})
Expand Down
4 changes: 2 additions & 2 deletions packages/viem-account-ledger/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export async function assertCompat(ledger: Eth): Promise<{
`Beware, you opened the Ethereum app instead of the Celo app. Some features may not work correctly, including token transfers.`
)
} else {
throw new Error(
`Beware, you opened the ${appName} app instead of the Celo app. We cannot ensure the safety of using this SDK with ${appName}.`
console.error(
`\n---\nBeware, you opened the ${appName} app instead of the Celo app. We cannot ensure the safety of using this SDK with ${appName}. USE AT YOUR OWN RISK.\n---\n`
)
}
if (!appConfiguration.arbitraryDataEnabled) {
Expand Down
Loading