diff --git a/src/CashuWallet.ts b/src/CashuWallet.ts index 00d4c993..79c9d98a 100644 --- a/src/CashuWallet.ts +++ b/src/CashuWallet.ts @@ -26,7 +26,8 @@ import { bytesToNumber, getDecodedToken, getDefaultAmountPreference, - splitAmount + splitAmount, + sumProofs } from './utils'; import { validateMnemonic } from '@scure/bip39'; import { wordlist } from '@scure/bip39/wordlists/english'; @@ -443,7 +444,7 @@ class CashuWallet { const keys = await this.getKeys(options?.keysetId); const { blindedMessages, secrets, rs } = this.createBlankOutputs( - meltQuote.fee_reserve, + sumProofs(proofsToSend) - meltQuote.amount, keys.id, options?.counter ); @@ -463,6 +464,8 @@ class CashuWallet { }; } + + /** * Helper function that pays a Lightning invoice directly without having to create a melt quote before * The combined amount of Proofs must match the payment amount including fees. diff --git a/src/utils.ts b/src/utils.ts index a4e55777..edb01c04 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -4,6 +4,9 @@ import { TOKEN_PREFIX, TOKEN_VERSION } from './utils/Constants'; import { bytesToHex, hexToBytes } from '@noble/curves/abstract/utils'; import { sha256 } from '@noble/hashes/sha256'; +export function sumProofs(proofs: Array) { + return proofs.reduce((acc: number, proof: Proof) => acc + proof.amount, 0); +} function splitAmount(value: number, amountPreference?: Array): Array { const chunks: Array = [];