Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Dipun Mistry <[email protected]>
  • Loading branch information
gandlafbtc and dipunm authored Nov 5, 2023
1 parent 691ba50 commit fe4b80f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/CashuWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,9 @@ class CashuWallet {

/**
* Regenerates
* @param count? set number of blinded messages that should be generated
* @param count set number of blinded messages that should be generated
* @param startIndex optionally set starting point for count (default is 0)
* @returns proofs and newKeys if they have changed
* @returns proofs (and newKeys, if they have changed)
*/
async restore(
count: number,
Expand All @@ -358,6 +358,7 @@ class CashuWallet {
if (!this._seed) {
throw new Error('CashuWallet must be initialized with mnemonic to use restore');
}
// create blank amounts for unknown restore amounts
const amounts = Array(count).fill(0);
const { blindedMessages, rs, secrets } = this.createBlindedMessages(amounts, startIndex, keysetId);

Expand Down Expand Up @@ -484,7 +485,7 @@ class CashuWallet {
/**
* Creates blinded messages for a given amount
* @param amount amount to create blinded messages for
* @param preference optional preference for splitting proofs into specific amounts. overrides amount param
* @param amountPreference optional preference for splitting proofs into specific amounts. overrides amount param
* @param count? optionally set count to derive secret deterministically. CashuWallet class must be initialized with seed phrase to take effect
* @returns blinded messages, secrets, rs, and amounts
*/
Expand All @@ -501,6 +502,7 @@ class CashuWallet {
* Creates blinded messages for a according to @param amounts
* @param amount array of amounts to create blinded messages for
* @param count? optionally set count to derive secret deterministically. CashuWallet class must be initialized with seed phrase to take effect
* @param keyksetId? override the keysetId derived from the current mintKeys with a custom one. This should be a keyset that was fetched from the `/keysets` endpoint
* @returns blinded messages, secrets, rs, and amounts
*/
private createBlindedMessages(
Expand All @@ -526,7 +528,7 @@ class CashuWallet {
const blindedMessage = new BlindedMessage(amounts[i], B_);
blindedMessages.push(blindedMessage.getSerializedBlindedMessage());
}
return { amounts, blindedMessages, rs, secrets };
return { blindedMessages, secrets, rs, amounts };
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/model/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ export type GetInfoResponse = {
parameter: { peg_out_only: boolean };
};
/**
* Response from mint at /info endpoint
* Response from mint at /restore endpoint
*/
export type PostRestoreResponse = {
outputs: Array<SerializedBlindedMessage>;
Expand Down
3 changes: 0 additions & 3 deletions src/secrets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import { bytesToNumber } from './utils';
import { hexToNumber } from '@noble/curves/abstract/utils';
export const generateNewMnemonic = (): string => {
const mnemonic = generateMnemonic(wordlist, 128);
if (!validateMnemonic(mnemonic, wordlist)) {
return generateNewMnemonic();
}
return mnemonic;
};

Expand Down

0 comments on commit fe4b80f

Please sign in to comment.