Skip to content

Commit

Permalink
Pass through decryptForSpender flag to note decryption (#5671)
Browse files Browse the repository at this point in the history
  • Loading branch information
dguenther authored Nov 26, 2024
1 parent f168064 commit 18dd964
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions ironfish/src/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
} from '../utils'
import { WorkerPool } from '../workerPool'
import { DecryptedNote, DecryptNotesItem } from '../workerPool/tasks/decryptNotes'
import { DecryptNotesOptions } from '../workerPool/tasks/decryptNotes'
import { Account, ACCOUNT_SCHEMA_VERSION } from './account/account'
import { EncryptedAccount } from './account/encryptedAccount'
import { AssetBalances } from './assetBalances'
Expand Down Expand Up @@ -418,13 +419,21 @@ export class Wallet {
}

if (accounts.length * decryptNotesPayloads.length >= workloadSize) {
notePromises.push(this.decryptNotesFromTransaction(accounts, decryptNotesPayloads))
notePromises.push(
this.decryptNotesFromTransaction(accounts, decryptNotesPayloads, {
decryptForSpender,
}),
)
decryptNotesPayloads = []
}
}

if (decryptNotesPayloads.length) {
notePromises.push(this.decryptNotesFromTransaction(accounts, decryptNotesPayloads))
notePromises.push(
this.decryptNotesFromTransaction(accounts, decryptNotesPayloads, {
decryptForSpender,
}),
)
}

const mergedResults: Map<string, Array<DecryptedNote>> = new Map()
Expand All @@ -448,6 +457,7 @@ export class Wallet {
private decryptNotesFromTransaction(
accounts: ReadonlyArray<Account>,
encryptedNotes: Array<DecryptNotesItem>,
options: DecryptNotesOptions,
): Promise<Map<string, Array<DecryptedNote | undefined>>> {
const accountKeys = accounts.map((account) => ({
accountId: account.id,
Expand All @@ -456,9 +466,7 @@ export class Wallet {
viewKey: Buffer.from(account.viewKey, 'hex'),
}))

return this.workerPool.decryptNotes(accountKeys, encryptedNotes, {
decryptForSpender: false,
})
return this.workerPool.decryptNotes(accountKeys, encryptedNotes, options)
}

async connectBlockForAccount(
Expand Down

0 comments on commit 18dd964

Please sign in to comment.