-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
269 additions
and
218 deletions.
There are no files selected for viewing
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,16 +1,18 @@ | ||
const bip44 = { | ||
createDerivePath(network) { | ||
/* | ||
In fact, not every testnet of coins has an index of 1 | ||
Therefore, specify the testnet coin index in the settings | ||
*/ | ||
type Path = string | ||
|
||
const { coinIndex } = network.settings.bip44 | ||
const addressIndex = 0 | ||
const createDerivePath = ({ coinIndex, addressIndex }: { | ||
coinIndex: number, | ||
addressIndex: number | ||
}): Path => { | ||
/* | ||
In fact, not every testnet of coins has an index of 1 | ||
Therefore, specify the testnet coin index in the settings | ||
*/ | ||
|
||
const path = `m/44'/${coinIndex}'/0'/0/${addressIndex}` | ||
return path | ||
} | ||
const path = `m/44'/${coinIndex}'/0'/0/${addressIndex}` | ||
return path | ||
} | ||
|
||
export default bip44 | ||
export default { | ||
createDerivePath | ||
} |
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
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,66 +1,25 @@ | ||
/* | ||
seed + password + HD Path => private key | ||
private key => public key | ||
public key => public address | ||
*/ | ||
|
||
type TMnemonic = string | ||
type TPrivateKey = string | ||
type TPublicKey = string | ||
type TAddress = string | ||
|
||
type TNetworkName = string | ||
|
||
type TProfile = { | ||
privateKey: TPrivateKey | ||
publicKey: TPublicKey | ||
address: TAddress | ||
} | ||
|
||
export enum ENetworkType { | ||
Mainnet = 'Mainnet', | ||
Testnet = 'Testnet' | ||
} | ||
|
||
export enum EPreset { | ||
BIP44 = 'BIP44', | ||
electrum = 'electrum' | ||
} | ||
|
||
export interface IAddProfileParams { | ||
mnemonic?: TMnemonic | ||
} | ||
|
||
export interface ICreateAddressesParams { | ||
coin: 'BTC' | 'LTC' | 'ETH' | ||
preset: EPreset | ||
} | ||
|
||
export interface INetwork { | ||
type: ENetworkType | ||
settings: { | ||
port: number | ||
magic: number | ||
messagePrefix: string | ||
base58prefix: { | ||
pubKeyHash: number | ||
scriptHash: number | ||
privateKeyWIF: number | ||
publicKeyBIP32: number | ||
privateKeyBIP32: number | ||
} | ||
bip44: { | ||
coinIndex: number | ||
} | ||
import coins from './coins' | ||
import { TProfile } from './types' | ||
|
||
/* interface IProfileFromMnemonicParams { | ||
typeof coins.BTC.profileFromMnemonic || | ||
typeof coins.LTC.profileFromMnemonic | ||
} */ | ||
|
||
const profileFromMnemonic: (params) => TProfile = params => { | ||
// todo: improve types - unreliable | ||
if (params.coin === 'BTC') { | ||
return coins.BTC.profileFromMnemonic(params) | ||
} | ||
if (params.coin === 'LTC') { | ||
return coins.LTC.profileFromMnemonic(params) | ||
} | ||
if (params.coin === 'ETH') { | ||
return coins.ETH.profileFromMnemonic(params) | ||
} | ||
throw new Error(`Unknown coin "${params.coin}"`) | ||
} | ||
|
||
export interface ICoin { | ||
symbol: string | ||
name: string | ||
precision: number | ||
networks: { | ||
[key: string]: INetwork | ||
} | ||
profileFromMnemonic: ({ mnemonic: TMnemonic, netName: TNetworkName, index: number }) => TProfile | ||
export default { | ||
profileFromMnemonic | ||
} |
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
seed + password + HD Path => private key | ||
private key => public key | ||
public key => public address | ||
*/ | ||
|
||
export type TMnemonic = string | ||
export type TPrivateKey = string | ||
export type TPublicKey = string | ||
export type TAddress = string | ||
|
||
export type TNetworkName = string | ||
|
||
export type TProfile = { | ||
privateKey: TPrivateKey | ||
publicKey: TPublicKey | ||
address: TAddress | ||
} | ||
|
||
export enum ENetworkType { | ||
Mainnet = 'Mainnet', | ||
Testnet = 'Testnet' | ||
} | ||
|
||
export enum EPreset { | ||
BIP44 = 'BIP44', | ||
electrum = 'electrum' | ||
} | ||
|
||
export interface IAddProfileParams { | ||
mnemonic?: TMnemonic | ||
} | ||
|
||
export interface ICreateAddressesParams { | ||
coin: 'BTC' | 'LTC' | 'ETH' | ||
preset: EPreset | ||
} | ||
|
||
export interface INetwork { | ||
type: ENetworkType | ||
settings: { | ||
port: number | ||
magic: number | ||
messagePrefix: string | ||
base58prefix: { | ||
pubKeyHash: number | ||
scriptHash: number | ||
privateKeyWIF: number | ||
publicKeyBIP32: number | ||
privateKeyBIP32: number | ||
} | ||
bip44: { | ||
coinIndex: number | ||
} | ||
} | ||
} | ||
|
||
export interface ICoin { | ||
symbol: string | ||
name: string | ||
precision: number | ||
networks: { | ||
[key: string]: INetwork | ||
} | ||
profileFromMnemonic: ({ mnemonic: TMnemonic, network: TNetworkName, addressIndex: number }) => TProfile | ||
} |
Oops, something went wrong.