Skip to content

Commit 25b773f

Browse files
authored
Merge pull request bitpay#2059 from micahriggan/chore/package-lock-eslint
prep wallet-ui
2 parents 4b7f151 + ebe1fd0 commit 25b773f

File tree

16 files changed

+11835
-9868
lines changed

16 files changed

+11835
-9868
lines changed

packages/bitcore-build/package-lock.json

Lines changed: 1184 additions & 1184 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/bitcore-client/package-lock.json

Lines changed: 2428 additions & 370 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/bitcore-client/src/wallet.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class Wallet {
3939
xPubKey: string;
4040
name: string;
4141
path: string;
42-
addressIndex: number;
42+
addressIndex?: number;
4343
authKey: string;
4444
derivationPath: string;
4545

@@ -115,7 +115,6 @@ export class Wallet {
115115
encryptionKey,
116116
authKey,
117117
authPubKey,
118-
addressIndex: 0,
119118
masterKey: encPrivateKey,
120119
password: await Bcrypt.hash(password, 10),
121120
xPubKey: hdPrivKey.xpubkey,
@@ -339,16 +338,20 @@ export class Wallet {
339338
this.addressIndex,
340339
isChange
341340
);
342-
await this.importKeys({ keys: [keyToImport] });
343-
return keyToImport.address.toString();
341+
return keyToImport;
344342
}
345343

346-
async nextAddressPair() {
347-
this.addressIndex =
348-
this.addressIndex !== undefined ? this.addressIndex + 1 : 0;
349-
const newAddress = await this.derivePrivateKey(false);
350-
const newChangeAddress = await this.derivePrivateKey(true);
344+
async nextAddressPair(withChangeAddress?: boolean) {
345+
this.addressIndex = this.addressIndex || 0;
346+
const newPrivateKey = await this.derivePrivateKey(false);
347+
const keys = [newPrivateKey];
348+
if (withChangeAddress) {
349+
const newChangePrivateKey = await this.derivePrivateKey(true);
350+
keys.push(newChangePrivateKey);
351+
}
352+
this.addressIndex++;
353+
await this.importKeys({ keys });
351354
await this.saveWallet();
352-
return [newAddress, newChangeAddress];
355+
return keys.map(key => key.address.toString());
353356
}
354357
}

0 commit comments

Comments
 (0)