Merge branch 'master' into feature/trusted-keys
This commit is contained in:
commit
41306c5b8a
2 changed files with 52 additions and 18 deletions
|
|
@ -31,8 +31,6 @@ module.exports = (mainnet = false) => {
|
||||||
return {
|
return {
|
||||||
serverPort: 9835,
|
serverPort: 9835,
|
||||||
serverHost: "localhost",
|
serverHost: "localhost",
|
||||||
sessionSecret: "my session secret",
|
|
||||||
sessionMaxAge: 300000,
|
|
||||||
lndAddress: "127.0.0.1:9735",
|
lndAddress: "127.0.0.1:9735",
|
||||||
maxNumRoutesToQuery: 20,
|
maxNumRoutesToQuery: 20,
|
||||||
lndProto: parsePath(`${__dirname}/rpc.proto`),
|
lndProto: parsePath(`${__dirname}/rpc.proto`),
|
||||||
|
|
@ -50,6 +48,6 @@ module.exports = (mainnet = false) => {
|
||||||
lndDirPath: lndDirectory,
|
lndDirPath: lndDirectory,
|
||||||
peers: ['http://gun.shock.network:8765/gun'],
|
peers: ['http://gun.shock.network:8765/gun'],
|
||||||
useTLS: false,
|
useTLS: false,
|
||||||
tokenExpirationMS: 4500000
|
tokenExpirationMS: 259200000
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -274,25 +274,29 @@ module.exports = async (
|
||||||
) {
|
) {
|
||||||
return next()
|
return next()
|
||||||
}
|
}
|
||||||
|
let reqData = null
|
||||||
const { data } = req.body
|
let IV = null
|
||||||
let IV = req.body.iv
|
let encryptedKey = null
|
||||||
let encryptedKey = req.body.encryptionKey
|
let encryptedToken = null
|
||||||
let encryptedToken = req.body.token
|
|
||||||
if (req.method === 'GET' || req.method === 'DELETE') {
|
if (req.method === 'GET' || req.method === 'DELETE') {
|
||||||
if (req.headers['x-shock-encryption-token']) {
|
if (req.headers['x-shock-encryption-token']) {
|
||||||
encryptedToken = req.headers['x-shock-encryption-token']
|
encryptedToken = req.headers['x-shock-encryption-token']
|
||||||
encryptedKey = req.headers['x-shock-encryption-key']
|
encryptedKey = req.headers['x-shock-encryption-key']
|
||||||
IV = req.headers['x-shock-encryption-iv']
|
IV = req.headers['x-shock-encryption-iv']
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
encryptedToken = req.body.token
|
||||||
|
encryptedKey = req.body.encryptionKey
|
||||||
|
IV = req.body.iv
|
||||||
|
reqData = req.body.data
|
||||||
}
|
}
|
||||||
const decryptedKey = Encryption.decryptKey({
|
const decryptedKey = Encryption.decryptKey({
|
||||||
deviceId,
|
deviceId,
|
||||||
message: encryptedKey
|
message: encryptedKey
|
||||||
})
|
})
|
||||||
if (data) {
|
if (reqData) {
|
||||||
const decryptedMessage = Encryption.decryptMessage({
|
const decryptedMessage = Encryption.decryptMessage({
|
||||||
message: data,
|
message: reqData,
|
||||||
key: decryptedKey,
|
key: decryptedKey,
|
||||||
iv: IV
|
iv: IV
|
||||||
})
|
})
|
||||||
|
|
@ -1427,17 +1431,49 @@ module.exports = async (
|
||||||
app.post('/api/lnd/sendpayment', (req, res) => {
|
app.post('/api/lnd/sendpayment', (req, res) => {
|
||||||
const { router } = LightningServices.services
|
const { router } = LightningServices.services
|
||||||
// this is the recommended value from lightning labs
|
// this is the recommended value from lightning labs
|
||||||
const { maxParts = 3, payreq } = req.body
|
let paymentRequest = {}
|
||||||
|
const { keysend, maxParts = 3, timeoutSeconds = 5 } = req.body
|
||||||
|
if (keysend) {
|
||||||
|
const { dest, amt, finalCltvDelta = 40 } = req.body
|
||||||
|
if (!dest || !amt) {
|
||||||
|
return res.status(500).json({
|
||||||
|
errorMessage: 'please provide "dest" and "amt" for keysend payments'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
const preimage = Crypto.randomBytes(32)
|
||||||
|
const r_hash = Crypto.createHash('sha256')
|
||||||
|
.update(preimage)
|
||||||
|
.digest()
|
||||||
|
//https://github.com/lightningnetwork/lnd/blob/master/record/experimental.go#L5:2
|
||||||
|
//might break in future updates
|
||||||
|
const KeySendType = 5482373484
|
||||||
|
//https://api.lightning.community/#featurebit
|
||||||
|
const TLV_ONION_REQ = 8
|
||||||
|
paymentRequest = {
|
||||||
|
dest: Buffer.from(dest, 'hex'),
|
||||||
|
amt,
|
||||||
|
final_cltv_delta: finalCltvDelta,
|
||||||
|
dest_features: [TLV_ONION_REQ],
|
||||||
|
dest_custom_records: {
|
||||||
|
[KeySendType]: preimage
|
||||||
|
},
|
||||||
|
payment_hash: r_hash,
|
||||||
|
max_parts: maxParts,
|
||||||
|
timeout_seconds: timeoutSeconds
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const { payreq } = req.body
|
||||||
|
|
||||||
const paymentRequest = {
|
paymentRequest = {
|
||||||
payment_request: payreq,
|
payment_request: payreq,
|
||||||
max_parts: maxParts,
|
max_parts: maxParts,
|
||||||
timeout_seconds: 5
|
timeout_seconds: timeoutSeconds
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.body.amt) {
|
if (req.body.amt) {
|
||||||
paymentRequest.amt = req.body.amt
|
paymentRequest.amt = req.body.amt
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logger.info('Sending payment', paymentRequest)
|
logger.info('Sending payment', paymentRequest)
|
||||||
const sentPayment = router.sendPaymentV2(paymentRequest)
|
const sentPayment = router.sendPaymentV2(paymentRequest)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue