Skip to content

Commit bf15ba6

Browse files
committed
Small preimage check refactor
1 parent 0c98e76 commit bf15ba6

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

wallets/client/hooks/payment.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,13 @@ function useSendPayment () {
156156
WALLET_SEND_PAYMENT_TIMEOUT_MS)
157157

158158
// some wallets like Coinos will always immediately return success without providing the preimage
159-
if (preimage) {
160-
if (!verifyPreimage(invoice, preimage)) {
161-
logger.warn('wallet returned success with invalid proof of payment')
162-
} else {
163-
logger.ok(`↗ payment sent: ${formatSats(invoice.satsRequested)}`)
164-
}
165-
} else {
166-
logger.warn('wallet returned success without proof of payment')
159+
if (!preimage) {
160+
return logger.warn('wallet returned success without proof of payment')
161+
}
162+
if (!verifyPreimage(invoice.hash, preimage)) {
163+
return logger.warn('wallet returned success with invalid proof of payment')
167164
}
165+
logger.ok(`↗ payment sent: ${formatSats(invoice.satsRequested)}`)
168166
} catch (err) {
169167
// we don't log the error here since we want to handle receiver errors separately
170168
const message = err.message || err.toString?.()
@@ -173,7 +171,7 @@ function useSendPayment () {
173171
}, [])
174172
}
175173

176-
function verifyPreimage (invoice, preimage) {
174+
function verifyPreimage (hash, preimage) {
177175
const preimageHash = Buffer.from(sha256(Buffer.from(preimage, 'hex'))).toString('hex')
178-
return invoice.hash === preimageHash
176+
return hash === preimageHash
179177
}

0 commit comments

Comments
 (0)