FIX: groundcontrol notifications for internal invoices
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
var crypto = require('crypto');
|
||||
var lightningPayReq = require('bolt11');
|
||||
|
||||
export class Invo {
|
||||
@@ -65,6 +66,31 @@ export class Invo {
|
||||
return await this._redis.get('ispaid_' + paymentHash);
|
||||
}
|
||||
|
||||
async getPreimage() {
|
||||
if (!this._bolt11) throw new Error('bolt11 is not provided');
|
||||
const decoded = lightningPayReq.decode(this._bolt11);
|
||||
let paymentHash = false;
|
||||
for (const tag of decoded.tags) {
|
||||
if (tag.tagName === 'payment_hash') {
|
||||
paymentHash = tag.data;
|
||||
}
|
||||
}
|
||||
if (!paymentHash) throw new Error('Could not find payment hash in invoice tags');
|
||||
return await this._redis.get('preimage_for_' + paymentHash);
|
||||
}
|
||||
|
||||
async savePreimage(preimageHex) {
|
||||
const paymentHashHex = require('crypto').createHash('sha256').update(Buffer.from(preimageHex, 'hex')).digest('hex');
|
||||
const key = 'preimage_for_' + paymentHashHex;
|
||||
await this._redis.set(key, preimageHex);
|
||||
await this._redis.expire(key, 3600 * 24 * 30); // 1 month
|
||||
}
|
||||
|
||||
makePreimageHex() {
|
||||
let buffer = crypto.randomBytes(32);
|
||||
return buffer.toString('hex');
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries LND ofr all user invoices
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user