-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix dpath * Fix Ledger testnet dpath + add fix testnet dpaths + add dpath to dcent + document and test dpaths * Fix comments * Lint Co-authored-by: Diego Grasso <[email protected]> Co-authored-by: Ilan <[email protected]> Co-authored-by: Ilan <[email protected]>
- Loading branch information
1 parent
0e28fd6
commit e3506f9
Showing
12 changed files
with
157 additions
and
21,287 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
3,345 changes: 20 additions & 3,325 deletions
3,345
packages/rlogin-dcent-provider/package-lock.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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 |
---|---|---|
@@ -1,11 +1,29 @@ | ||
export const getDPathByChainId = (chainId: number): string => { | ||
/** | ||
* Get the BIP-44 account derivation path for a given network and index. The network | ||
* is the return value for RPC eth_chainId | ||
* Standards: | ||
* - BIP-44: https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki | ||
* - SLIP-44: https://github.com/satoshilabs/slips/blob/master/slip-0044.md | ||
* - RSKIP-57: https://github.com/rsksmart/RSKIPs/blob/master/IPs/RSKIP57.md | ||
* - EIP-155: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md | ||
* - EIP-695: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-695.md | ||
* @param chainId EIP-155 chain Id | ||
* @param index derive different accounts based on SLIP-44 | ||
* @param isLedger use it for RSK Testnet and Ledger | ||
* @returns the first account of standard BIP-44 derviation path forthe given network | ||
*/ | ||
|
||
export const getDPathByChainId = (chainId: number, index: number = 0, isLedger = false): string => { | ||
if (isLedger && chainId === 31) return `m/44'/1'/0'/0/${index}` // Ledger + RSK Testnet - based on slip-44 - 37310 does not work | ||
switch (chainId) { | ||
case 30: return "44'/137'/0'/0/0" | ||
case 31: | ||
case 1: | ||
case 3: | ||
case 4: | ||
case 5: return "m/44'/60'/0'/0/0" | ||
case 30: return `m/44'/137'/0'/0/${index}` // RSK Mainnet - based on rskip-57 | ||
case 31: return `m/44'/37310'/0'/0/${index}` // RSK Testnet - based on rskip-57 | ||
case 1: return `m/44'/60'/0'/0/${index}` // Ethereum Mainnet - based on eip-155 and slip-44 | ||
case 3:// Ropsten | ||
case 4:// Rinkeby | ||
case 5:// Goerli | ||
case 42: // Kovan | ||
return `m/44'/1'/0'/0/${index}` // Ethereum testnets - based on eip-155 and slip-44 | ||
default: throw new Error('Network not supported please specify the derivation path') | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -1,5 +1,30 @@ | ||
describe('test', () => { | ||
test('test', () => { | ||
expect(true).toBeTruthy() | ||
import { getDPathByChainId } from '../src/index' | ||
|
||
const testCases = [ | ||
{ title: 'rsk mainnet', chainId: 30, 0: 'm/44\'/137\'/0\'/0/0', 2: 'm/44\'/137\'/0\'/0/2' }, | ||
{ title: 'rsk testnet', chainId: 31, 0: 'm/44\'/37310\'/0\'/0/0', 2: 'm/44\'/37310\'/0\'/0/2', forLedeger: 'm/44\'/1\'/0\'/0/0' }, | ||
{ title: 'ethereum', chainId: 1, 0: 'm/44\'/60\'/0\'/0/0', 2: 'm/44\'/60\'/0\'/0/2' }, | ||
...[ | ||
{ title: 'ropsten', chainId: 3 }, | ||
{ title: 'rinkeby', chainId: 4 }, | ||
{ title: 'goreli', chainId: 5 }, | ||
{ title: 'kovan', chainId: 42 } | ||
].map(({ title, chainId }) => ({ | ||
title, chainId, 0: 'm/44\'/1\'/0\'/0/0', 2: 'm/44\'/1\'/0\'/0/2' | ||
})) | ||
] | ||
describe('dpath for network id', () => { | ||
for (const testCase of testCases) { | ||
test(testCase.title, () => { | ||
expect(getDPathByChainId(testCase.chainId)).toEqual(testCase['0']) | ||
expect(getDPathByChainId(testCase.chainId, 2)).toEqual(testCase['2']) | ||
expect(getDPathByChainId(testCase.chainId, 0, true)).toEqual(testCase.forLedeger || testCase['0']) | ||
}) | ||
} | ||
|
||
test('throws for other coins', () => { | ||
expect(() => getDPathByChainId(200)).toThrow() | ||
expect(() => getDPathByChainId(200, 2)).toThrow() | ||
expect(() => getDPathByChainId(200, 2, true)).toThrow() | ||
}) | ||
}) |
248 changes: 2 additions & 246 deletions
248
packages/rlogin-eip1193-proxy-subprovider/package-lock.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.