chore: move decryptLnurlPayAES to utils (#3576)

This commit is contained in:
dni ⚡
2025-11-26 19:40:54 +01:00
committed by GitHub
parent f1f6af0e35
commit 49cc8104fc
8 changed files with 38 additions and 34 deletions
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+4 -4
View File
@@ -111,11 +111,11 @@ window.app.component('lnbits-lnurlpay-success-action', {
},
mounted() {
if (this.success_action.tag !== 'aes') return null
decryptLnurlPayAES(this.success_action, this.payment.preimage).then(
value => {
this.utils
.decryptLnurlPayAES(this.success_action, this.payment.preimage)
.then(value => {
this.decryptedValue = value
}
)
})
}
})
-23
View File
@@ -1,23 +0,0 @@
window.decryptLnurlPayAES = (success_action, preimage) => {
let keyb = new Uint8Array(
preimage.match(/[\da-f]{2}/gi).map(h => parseInt(h, 16))
)
return crypto.subtle
.importKey('raw', keyb, {name: 'AES-CBC', length: 256}, false, ['decrypt'])
.then(key => {
let ivb = Uint8Array.from(window.atob(success_action.iv), c =>
c.charCodeAt(0)
)
let ciphertextb = Uint8Array.from(
window.atob(success_action.ciphertext),
c => c.charCodeAt(0)
)
return crypto.subtle.decrypt({name: 'AES-CBC', iv: ivb}, key, ciphertextb)
})
.then(valueb => {
let decoder = new TextDecoder('utf-8')
return decoder.decode(valueb)
})
}
+1 -1
View File
@@ -456,7 +456,7 @@ window.PageWallet = {
})
break
case 'aes':
decryptLnurlPayAES(action, response.data.preimage)
this.utils.decryptLnurlPayAES(action, response.data.preimage)
Quasar.Notify.create({
message: value,
caption: extra.success_action.description,
+29
View File
@@ -171,5 +171,34 @@ window._lnbitsUtils = {
converter.setFlavor('github')
converter.setOption('simpleLineBreaks', true)
return converter.makeHtml(text)
},
async decryptLnurlPayAES(success_action, preimage) {
let keyb = new Uint8Array(
preimage.match(/[\da-f]{2}/gi).map(h => parseInt(h, 16))
)
return crypto.subtle
.importKey('raw', keyb, {name: 'AES-CBC', length: 256}, false, [
'decrypt'
])
.then(key => {
let ivb = Uint8Array.from(window.atob(success_action.iv), c =>
c.charCodeAt(0)
)
let ciphertextb = Uint8Array.from(
window.atob(success_action.ciphertext),
c => c.charCodeAt(0)
)
return crypto.subtle.decrypt(
{name: 'AES-CBC', iv: ivb},
key,
ciphertextb
)
})
.then(valueb => {
let decoder = new TextDecoder('utf-8')
return decoder.decode(valueb)
})
}
}
+1 -2
View File
@@ -39,8 +39,7 @@
"js/base.js",
"js/windowMixin.js",
"js/event-reactions.js",
"js/bolt11-decoder.js",
"js/lnurl.js"
"js/bolt11-decoder.js"
],
"components": [
"js/pages/home.js",
+1 -2
View File
@@ -91,8 +91,7 @@
"js/base.js",
"js/windowMixin.js",
"js/event-reactions.js",
"js/bolt11-decoder.js",
"js/lnurl.js"
"js/bolt11-decoder.js"
],
"components": [
"js/pages/home.js",