mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-02-11 10:36:53 +00:00
* Update account view routing * Temporarily add unicode character to translated strings for testing * Temporarily select add unicode to all untranslated strings * Format changes * Add all english translations for /account & /generate * Add the rest of the english translations * Add a few more missing translations * Update en translations * Get selectedLanguage from localstorage instead of redux sttate * Update snapshots * Add missing translation keys & Update translate functs & change variable prefix * translate all markdown strings & remove old translation strings * Update snapshot * Add a few more translation strs * Move raw strings being translated into json * All translation keys are now Uppercase * Fix up the last few translations * Update snapshot * Uppercase de translation strings * Bring back shapeshift logo on swap * Fix contracts tab translations * Fix a few more translations * Fix translations * remove debugging stuff * Update snapshots * Use react.fragment as markdown root renderer * Seperate markdown translations into their own function * Clean up translation functions * Clean up translation functions * Update snapshot * Fix some broken translation strings * Add prettier ignore file
93 lines
2.7 KiB
TypeScript
93 lines
2.7 KiB
TypeScript
import ledger from 'ledgerco';
|
|
import EthTx, { TxObj } from 'ethereumjs-tx';
|
|
import { addHexPrefix, bufferToHex, toBuffer } from 'ethereumjs-util';
|
|
import { DeterministicWallet } from './deterministic';
|
|
import { getTransactionFields } from 'libs/transaction';
|
|
import { IFullWallet } from '../IWallet';
|
|
import { translateRaw } from 'translations';
|
|
|
|
export class LedgerWallet extends DeterministicWallet implements IFullWallet {
|
|
private ethApp: ledger.eth;
|
|
|
|
constructor(address: string, dPath: string, index: number) {
|
|
super(address, dPath, index);
|
|
ledger.comm_u2f.create_async().then((comm: any) => {
|
|
this.ethApp = new ledger.eth(comm);
|
|
});
|
|
}
|
|
|
|
// modeled after
|
|
// https://github.com/kvhnuke/etherwallet/blob/3f7ff809e5d02d7ea47db559adaca1c930025e24/app/scripts/uiFuncs.js#L58
|
|
public signRawTransaction(t: EthTx): Promise<Buffer> {
|
|
t.v = Buffer.from([t._chainId]);
|
|
t.r = toBuffer(0);
|
|
t.s = toBuffer(0);
|
|
|
|
return new Promise((resolve, reject) => {
|
|
this.ethApp
|
|
.signTransaction_async(this.getPath(), t.serialize().toString('hex'))
|
|
.then(result => {
|
|
const strTx = getTransactionFields(t);
|
|
const txToSerialize: TxObj = {
|
|
...strTx,
|
|
v: addHexPrefix(result.v),
|
|
r: addHexPrefix(result.r),
|
|
s: addHexPrefix(result.s)
|
|
};
|
|
|
|
const serializedTx = new EthTx(txToSerialize).serialize();
|
|
resolve(serializedTx);
|
|
})
|
|
.catch(err => {
|
|
return reject(Error(err + '. Check to make sure contract data is on'));
|
|
});
|
|
});
|
|
}
|
|
|
|
// modeled after
|
|
// https://github.com/kvhnuke/etherwallet/blob/3f7ff809e5d02d7ea47db559adaca1c930025e24/app/scripts/controllers/signMsgCtrl.js#L53
|
|
public signMessage(msg: string): Promise<string> {
|
|
const msgHex = Buffer.from(msg).toString('hex');
|
|
|
|
return new Promise((resolve, reject) => {
|
|
this.ethApp.signPersonalMessage_async(
|
|
this.getPath(),
|
|
msgHex,
|
|
async (signed: any, error: any) => {
|
|
if (error) {
|
|
return reject((this.ethApp as any).getError(error));
|
|
}
|
|
|
|
try {
|
|
const combined = signed.r + signed.s + signed.v;
|
|
resolve(bufferToHex(combined));
|
|
} catch (err) {
|
|
reject(err);
|
|
}
|
|
}
|
|
);
|
|
});
|
|
}
|
|
|
|
public displayAddress = (
|
|
dPath?: string,
|
|
index?: number
|
|
): Promise<{
|
|
publicKey: string;
|
|
address: string;
|
|
chainCode?: string;
|
|
}> => {
|
|
if (!dPath) {
|
|
dPath = this.dPath;
|
|
}
|
|
if (!index) {
|
|
index = this.index;
|
|
}
|
|
return this.ethApp.getAddress_async(dPath + '/' + index, true, false);
|
|
};
|
|
|
|
public getWalletType(): string {
|
|
return translateRaw('X_LEDGER');
|
|
}
|
|
}
|