24 lines
705 B
JavaScript
24 lines
705 B
JavaScript
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)
|
|
})
|
|
}
|