MyCrypto/common/libs/wallet/privkey.js

29 lines
630 B
JavaScript
Raw Normal View History

2017-06-29 23:03:11 +00:00
// @flow
import BaseWallet from './base';
2017-07-04 03:21:19 +00:00
import {
privateToPublic,
publicToAddress,
toChecksumAddress
} from 'ethereumjs-util';
2017-06-29 23:03:11 +00:00
export type PrivateKeyUnlockParams = {
2017-07-04 03:21:19 +00:00
key: string,
password: string
2017-06-29 23:03:11 +00:00
};
export default class PrivKeyWallet extends BaseWallet {
2017-07-04 03:21:19 +00:00
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);
}
2017-06-29 23:03:11 +00:00
2017-07-04 03:21:19 +00:00
getAddress() {
return toChecksumAddress(`0x${this.address.toString('hex')}`);
}
2017-06-29 23:03:11 +00:00
}