-
Notifications
You must be signed in to change notification settings - Fork 56
Derive Avalanche C-Chain addresses at coin type 60 #1057
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
Open
j0ntz
wants to merge
2
commits into
master
Choose a base branch
from
jon/fix-avax-evm-derivation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+68
−1
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import { assert } from 'chai' | ||
| import { | ||
| EdgeCorePluginOptions, | ||
| EdgeCurrencyPlugin, | ||
| EdgeCurrencyTools, | ||
| makeFakeIo | ||
| } from 'edge-core-js' | ||
| import { before, describe, it } from 'mocha' | ||
| import fetch from 'node-fetch' | ||
|
|
||
| import edgeCorePlugins from '../../src/index' | ||
| import { fakeLog } from '../fake/fakeLog' | ||
|
|
||
| // A 12-word seed and the receive address it yields on EVM wallets (Exodus, | ||
| // MetaMask, Trust) which all derive at coin type 60. Ethereum, Polygon and | ||
| // Avalanche C-Chain are all EVM, so importing this seed into Edge must produce | ||
| // the same address on each. Avalanche was the regression (it derived at coin | ||
| // type 9000); Ethereum and Polygon are the chains the report flagged as most | ||
| // important, so they are locked here too. | ||
| const MNEMONIC = | ||
| 'room soda device label bicycle hill fork nest lion knee purpose hen' | ||
| const EXPECTED_EVM_ADDRESS = '0x21D45Fd06e291C49AbFa135460DE827b6579Cef5' | ||
|
|
||
| const makeOpts = (): EdgeCorePluginOptions => { | ||
| const fakeIo = makeFakeIo() | ||
| return { | ||
| infoPayload: {}, | ||
| initOptions: {}, | ||
| io: { ...fakeIo, fetch, fetchCors: fetch }, | ||
| log: fakeLog, | ||
| nativeIo: {}, | ||
| pluginDisklet: fakeIo.disklet | ||
| } | ||
| } | ||
|
|
||
| const CASES = [ | ||
| { pluginId: 'ethereum', mnemonicKey: 'ethereumMnemonic' }, | ||
| { pluginId: 'polygon', mnemonicKey: 'polygonMnemonic' }, | ||
| { pluginId: 'avalanche', mnemonicKey: 'avalancheMnemonic' } | ||
| ] as const | ||
|
|
||
| describe('EVM derivation parity (coin type 60)', function () { | ||
| for (const { pluginId, mnemonicKey } of CASES) { | ||
| describe(pluginId, function () { | ||
| let tools: EdgeCurrencyTools | ||
|
|
||
| before('Tools', async function () { | ||
| const factory = edgeCorePlugins[pluginId] | ||
| const plugin: EdgeCurrencyPlugin = factory(makeOpts()) | ||
| tools = await plugin.makeCurrencyTools() | ||
| }) | ||
|
|
||
| it('derives the Exodus-matching EVM address from an imported seed', async function () { | ||
| const keys = await tools.derivePublicKey({ | ||
| id: 'id', | ||
| keys: { [mnemonicKey]: MNEMONIC }, | ||
| type: `wallet:${pluginId}` | ||
| }) | ||
| assert.equal(keys.publicKey, EXPECTED_EVM_ADDRESS) | ||
| }) | ||
| }) | ||
| } | ||
| }) |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an incomplete fix. Existing wallets opened on a new device will be derive an address at the new path. One way to resolve is to save the path when creating the wallet and have derive pubkey use it if it's present or fallback to another value if it isn't. I believe we've done this for polkadot tools or another currency tools in the past.
Another solution could be to finally support passing in the path as an optional import option. That would require we save the path in the keys object.