Merge pull request #84 from polymorpher/fix-hd-node

Optionally generateMnemonic during HDNode creation; Fix a bug with setSigner
dependabot/npm_and_yarn/ssri-6.0.2
Ganesha Upadhyaya 4 years ago committed by GitHub
commit e364c4ffea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      packages/harmony-account/src/hdnode.ts

@ -96,7 +96,9 @@ export class HDNode {
this.path = chainType === ChainType.Harmony ? HDPath : `m/44'/60'/0'/0/`;
this.index = index;
this.addressCount = addressCount;
this.getHdWallet(menmonic || HDNode.generateMnemonic());
if (menmonic !== null && menmonic !== '') {
this.getHdWallet(menmonic || HDNode.generateMnemonic());
}
this.gasLimit = gasLimit;
this.gasPrice = gasPrice;
}
@ -151,6 +153,7 @@ export class HDNode {
}
return this.addresses;
}
// tslint:disable-next-line: ban-types
getPrivateKey(address: string, cb?: Function) {
if (!cb) {
@ -166,6 +169,7 @@ export class HDNode {
cb(null, this.wallets[address].privateKey);
}
}
// tslint:disable-next-line: ban-types
async signTransaction(txParams: any | Web3TxPrams) {
const from: string = txParams.from ? getAddress(txParams.from).checksum : '0x';
@ -238,6 +242,7 @@ export class HDNode {
return signed.getRawTransaction();
}
getAddress(idx?: number) {
if (!idx) {
return this.addresses[0];
@ -245,9 +250,11 @@ export class HDNode {
return this.addresses[idx];
}
}
getAddresses() {
return this.addresses;
}
addByPrivateKey(privateKey: string) {
const account = new Account(privateKey);
const addr = account.checksumAddress;
@ -258,7 +265,7 @@ export class HDNode {
setSigner(address: string) {
const foundIndex = this.addresses.findIndex((value) => value === address);
this.addresses.slice(foundIndex, foundIndex + 1);
this.addresses.splice(foundIndex, 1);
this.addresses.unshift(address);
}
}

Loading…
Cancel
Save