provide more desc error in lnurl-auth
This commit is contained in:
parent
ed6a683b79
commit
8a054d55ff
|
@ -5,11 +5,11 @@ import secp256k1 from 'secp256k1'
|
|||
import models from '../../api/models'
|
||||
|
||||
export default async ({ query }, res) => {
|
||||
const sig = Buffer.from(query.sig, 'hex')
|
||||
const k1 = Buffer.from(query.k1, 'hex')
|
||||
const key = Buffer.from(query.key, 'hex')
|
||||
const signature = secp256k1.signatureImport(sig)
|
||||
try {
|
||||
const sig = Buffer.from(query.sig, 'hex')
|
||||
const k1 = Buffer.from(query.k1, 'hex')
|
||||
const key = Buffer.from(query.key, 'hex')
|
||||
const signature = secp256k1.signatureImport(sig)
|
||||
if (secp256k1.ecdsaVerify(signature, k1, key)) {
|
||||
await models.lnAuth.update({ where: { k1: query.k1 }, data: { pubkey: query.key } })
|
||||
return res.status(200).json({ status: 'OK' })
|
||||
|
@ -17,5 +17,14 @@ export default async ({ query }, res) => {
|
|||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
return res.status(400).json({ status: 'ERROR', reason: 'signature verification failed' })
|
||||
|
||||
let reason = 'signature verification failed'
|
||||
if (!query.sig) {
|
||||
reason = 'no sig query variable provided'
|
||||
} else if (!query.k1) {
|
||||
reason = 'no k1 query variable provided'
|
||||
} else if (!query.key) {
|
||||
reason = 'no key query variable provided'
|
||||
}
|
||||
return res.status(400).json({ status: 'ERROR', reason })
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue