4 changed files with 78 additions and 78 deletions
@ -1,32 +0,0 @@ |
|||
// @flow
|
|||
import type { CryptoCurrency } from '@ledgerhq/live-common/lib/types' |
|||
|
|||
function shouldDerivateChangeFieldInsteadOfAccount(c: CryptoCurrency) { |
|||
// ethereum have a special way of derivating things
|
|||
return c.id.indexOf('ethereum') === 0 |
|||
} |
|||
|
|||
// https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
|
|||
// x is a derivation index. we don't always derivate the same part of the path
|
|||
export function makeBip44Path({ |
|||
currency, |
|||
segwit, |
|||
x, |
|||
}: { |
|||
currency: CryptoCurrency, |
|||
segwit?: boolean, |
|||
x?: number, |
|||
}): string { |
|||
const purpose = segwit ? 49 : 44 |
|||
const coinType = currency.coinType |
|||
let path = `${purpose}'/${coinType}'` |
|||
if (shouldDerivateChangeFieldInsteadOfAccount(currency)) { |
|||
path += "/0'" |
|||
if (x !== undefined) { |
|||
path += `/${x}` |
|||
} |
|||
} else if (x !== undefined) { |
|||
path += `/${x}'` |
|||
} |
|||
return path |
|||
} |
@ -0,0 +1,29 @@ |
|||
// @flow
|
|||
import type { CryptoCurrency } from '@ledgerhq/live-common/lib/types' |
|||
|
|||
type Derivation = ({ |
|||
currency: CryptoCurrency, |
|||
segwit: boolean, |
|||
x: number, |
|||
}) => string |
|||
|
|||
const ethLegacyMEW: Derivation = ({ x }) => `44'/60'/0'/${x}` |
|||
|
|||
const etcLegacyMEW: Derivation = ({ x }) => `44'/60'/160720'/${x}` |
|||
|
|||
const legacyDerivations = { |
|||
ethereum: [ethLegacyMEW], |
|||
ethereum_classic: [etcLegacyMEW], |
|||
} |
|||
|
|||
export const standardDerivation: Derivation = ({ currency, segwit, x }) => { |
|||
const purpose = segwit ? 49 : 44 |
|||
const { coinType } = currency |
|||
return `${purpose}'/${coinType}'/${x}'/0/0` |
|||
} |
|||
|
|||
// return an array of ways to derivate, by convention the latest is the standard one.
|
|||
export const getDerivations = (currency: CryptoCurrency): Derivation[] => [ |
|||
...(legacyDerivations[currency.id] || []), |
|||
standardDerivation, |
|||
] |
Loading…
Reference in new issue