mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-02-16 04:57:08 +00:00
25 lines
662 B
JavaScript
25 lines
662 B
JavaScript
|
// @flow
|
||
|
import BaseWallet from './base';
|
||
|
import { privateToPublic, publicToAddress, toChecksumAddress } from 'ethereumjs-util';
|
||
|
|
||
|
export type PrivateKeyUnlockParams = {
|
||
|
key: string,
|
||
|
password: string
|
||
|
};
|
||
|
|
||
|
export default class PrivKeyWallet extends BaseWallet {
|
||
|
privKey: Buffer;
|
||
|
pubKey: Buffer;
|
||
|
address: Buffer;
|
||
|
constructor(params: PrivateKeyUnlockParams) {
|
||
|
super();
|
||
|
this.privKey = Buffer.from(params.key, 'hex');
|
||
|
this.pubKey = privateToPublic(this.privKey);
|
||
|
this.address = publicToAddress(this.pubKey);
|
||
|
}
|
||
|
|
||
|
getAddress() {
|
||
|
return toChecksumAddress(`0x${this.address.toString('hex')}`);
|
||
|
}
|
||
|
}
|