Pipeline: bug fix
- Add pipeline when CREATE_PIPELINE message is received - Fixed: 'User is not a part of this multisig' error shown incorrectly - Fixed various minor bugs - Added optional fee argument for multisig.createTx
This commit is contained in:
parent
5564b73299
commit
1bb6f7a280
@ -244,6 +244,7 @@
|
|||||||
throw "blocked-user";
|
throw "blocked-user";
|
||||||
if (unparsed.message instanceof Object && "secret" in unparsed.message)
|
if (unparsed.message instanceof Object && "secret" in unparsed.message)
|
||||||
unparsed.message = floDapps.user.decrypt(unparsed.message);
|
unparsed.message = floDapps.user.decrypt(unparsed.message);
|
||||||
|
let vc = unparsed.vectorClock;
|
||||||
switch (unparsed.type) {
|
switch (unparsed.type) {
|
||||||
case "MESSAGE": { //process as message
|
case "MESSAGE": { //process as message
|
||||||
let dm = {
|
let dm = {
|
||||||
@ -314,6 +315,19 @@
|
|||||||
groupInfo.eKey = eKey
|
groupInfo.eKey = eKey
|
||||||
newInbox.keyrevoke.push(groupInfo.groupID)
|
newInbox.keyrevoke.push(groupInfo.groupID)
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "CREATE_PIPELINE": { //add pipeline
|
||||||
|
let pipelineInfo = JSON.parse(unparsed.message);
|
||||||
|
let eKey = pipelineInfo.eKey;
|
||||||
|
pipelineInfo.eKey = encrypt(eKey)
|
||||||
|
compactIDB.addData("pipeline", {
|
||||||
|
...pipelineInfo
|
||||||
|
}, pipelineInfo.id);
|
||||||
|
pipelineInfo.eKey = eKey;
|
||||||
|
_loaded.pipeline[pipelineInfo.id] = pipelineInfo
|
||||||
|
requestPipelineInbox(pipelineInfo.id, pipelineInfo.model);
|
||||||
|
newInbox.pipeline[pipelineInfo.id] = pipelineInfo.model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -332,7 +346,8 @@
|
|||||||
messages: {},
|
messages: {},
|
||||||
mails: {},
|
mails: {},
|
||||||
newgroups: [],
|
newgroups: [],
|
||||||
keyrevoke: []
|
keyrevoke: [],
|
||||||
|
pipeline: {}
|
||||||
}
|
}
|
||||||
for (let vc in dataSet) {
|
for (let vc in dataSet) {
|
||||||
try {
|
try {
|
||||||
@ -784,7 +799,8 @@
|
|||||||
sender: unparsed.senderID,
|
sender: unparsed.senderID,
|
||||||
groupID: unparsed.receiverID
|
groupID: unparsed.receiverID
|
||||||
}
|
}
|
||||||
let k = _loaded.groups[groupID].eKey;
|
let vc = unparsed.vectorClock,
|
||||||
|
k = _loaded.groups[groupID].eKey;
|
||||||
if (expiredKeys[groupID]) {
|
if (expiredKeys[groupID]) {
|
||||||
var ex = Object.keys(expiredKeys[groupID]).sort()
|
var ex = Object.keys(expiredKeys[groupID]).sort()
|
||||||
while (ex.length && vc > ex[0]) ex.shift()
|
while (ex.length && vc > ex[0]) ex.shift()
|
||||||
@ -869,7 +885,7 @@
|
|||||||
}
|
}
|
||||||
compactIDB.writeData("appendix", _loaded.appendix[`lastReceived_${groupID}`], `lastReceived_${groupID}`);
|
compactIDB.writeData("appendix", _loaded.appendix[`lastReceived_${groupID}`], `lastReceived_${groupID}`);
|
||||||
if (infoChange) {
|
if (infoChange) {
|
||||||
let newInfo = Object.assign(_loaded.groups[groupID], {});
|
let newInfo = Object.assign({}, _loaded.groups[groupID]);
|
||||||
newInfo.eKey = encrypt(newInfo.eKey)
|
newInfo.eKey = encrypt(newInfo.eKey)
|
||||||
compactIDB.writeData("groups", newInfo, groupID)
|
compactIDB.writeData("groups", newInfo, groupID)
|
||||||
}
|
}
|
||||||
@ -971,7 +987,7 @@
|
|||||||
[floGlobals.application]: content
|
[floGlobals.application]: content
|
||||||
}), co_owners).then(txid => {
|
}), co_owners).then(txid => {
|
||||||
console.info(txid);
|
console.info(txid);
|
||||||
let key = TYPE_BTC_MULTISIG + "|" + tx.txid.substr(0, 16);
|
let key = TYPE_BTC_MULTISIG + "|" + txid.substr(0, 16);
|
||||||
compactIDB.writeData("flodata", {
|
compactIDB.writeData("flodata", {
|
||||||
time: null, //time will be overwritten when confirmed on blockchain
|
time: null, //time will be overwritten when confirmed on blockchain
|
||||||
txid: txid,
|
txid: txid,
|
||||||
@ -991,20 +1007,20 @@
|
|||||||
compactIDB.searchData("flodata", options).then(result => {
|
compactIDB.searchData("flodata", options).then(result => {
|
||||||
let multsigs = {};
|
let multsigs = {};
|
||||||
for (let i in result) {
|
for (let i in result) {
|
||||||
let addr = result[i].address;
|
let addr = result[i].data.address;
|
||||||
let decode = coinjs.script().decodeRedeemScript(result[i].redeemScript);
|
let decode = coinjs.script().decodeRedeemScript(result[i].data.redeemScript);
|
||||||
if (!decode || decode.address !== addr)
|
if (!decode || decode.address !== addr)
|
||||||
console.warn("Invalid redeem-script:", addr);
|
console.warn("Invalid redeem-script:", addr);
|
||||||
else if (decode.type !== "multisig__")
|
else if (decode.type !== "multisig__")
|
||||||
console.warn("Redeem-script is not of a multisig:", addr);
|
console.warn("Redeem-script is not of a multisig:", addr);
|
||||||
else if (!decode.pubKeys.includes(user.public))
|
else if (!decode.pubkeys.includes(user.public.toLowerCase()) && !decode.pubkeys.includes(user.public.toUpperCase()))
|
||||||
console.warn("User is not a part of this multisig:", addr);
|
console.warn("User is not a part of this multisig:", addr);
|
||||||
else if (decode.pubKeys.length < decode.signaturesRequired)
|
else if (decode.pubkeys.length < decode.signaturesRequired)
|
||||||
console.warn("Invalid multisig (required is greater than users):", addr);
|
console.warn("Invalid multisig (required is greater than users):", addr);
|
||||||
else
|
else
|
||||||
multsigs[addr] = {
|
multsigs[addr] = {
|
||||||
redeemScript: decode.redeemScript,
|
redeemScript: decode.redeemscript,
|
||||||
pubKeys: decode.pubKeys,
|
pubKeys: decode.pubkeys,
|
||||||
minRequired: decode.signaturesRequired
|
minRequired: decode.signaturesRequired
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1013,18 +1029,18 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiSig.createTx = function(address, redeemScript, receivers, amounts) {
|
MultiSig.createTx = function(address, redeemScript, receivers, amounts, fee = null) {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
let decode = coinjs.script().decodeRedeemScript(redeemScript);
|
let decode = coinjs.script().decodeRedeemScript(redeemScript);
|
||||||
if (!decode || decode.address !== address || decode.type !== "multisig__")
|
if (!decode || decode.address !== address || decode.type !== "multisig__")
|
||||||
return reject("Invalid redeem-script");
|
return reject("Invalid redeem-script");
|
||||||
else if (!decode.pubKeys.includes(user.public))
|
else if (!decode.pubkeys.includes(user.public.toLowerCase()) && !decode.pubkeys.includes(user.public.toUpperCase()))
|
||||||
return reject("User is not a part of this multisig");
|
return reject("User is not a part of this multisig");
|
||||||
else if (decode.pubKeys.length < decode.signaturesRequired)
|
else if (decode.pubkeys.length < decode.signaturesRequired)
|
||||||
return reject("Invalid multisig (required is greater than users)");
|
return reject("Invalid multisig (required is greater than users)");
|
||||||
let co_owners = decode.pubKeys.map(p => floCrypto.getFloID(p));
|
let co_owners = decode.pubkeys.map(p => floCrypto.getFloID(p));
|
||||||
let privateKey = await floDapps.user.private;
|
let privateKey = await floDapps.user.private;
|
||||||
btcOperator.createMultiSigTx(address, redeemScript, receivers, amounts, null).then(tx => {
|
btcOperator.createMultiSigTx(address, redeemScript, receivers, amounts, fee).then(tx => {
|
||||||
tx = btcOperator.signTx(tx, privateKey);
|
tx = btcOperator.signTx(tx, privateKey);
|
||||||
createPipeline(TYPE_BTC_MULTISIG, co_owners, 32).then(pipeline => {
|
createPipeline(TYPE_BTC_MULTISIG, co_owners, 32).then(pipeline => {
|
||||||
let message = encrypt(tx, pipeline.eKey);
|
let message = encrypt(tx, pipeline.eKey);
|
||||||
@ -1036,13 +1052,8 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiSig.signTx = function(pipeID, tx_hex, redeemScript) {
|
MultiSig.signTx = function(pipeID, tx_hex) {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
let decode = coinjs.script().decodeRedeemScript(redeemScript);
|
|
||||||
if (!decode || decode.type !== "multisig__")
|
|
||||||
return reject("Invalid redeem-script");
|
|
||||||
else if (!decode.pubKeys.includes(user.public))
|
|
||||||
return reject("User is not a part of this multisig");
|
|
||||||
let pipeline = _loaded.pipeline[pipeID],
|
let pipeline = _loaded.pipeline[pipeID],
|
||||||
tx = coinjs.transaction().deserialize(tx_hex);;
|
tx = coinjs.transaction().deserialize(tx_hex);;
|
||||||
let privateKey = await floDapps.user.private;
|
let privateKey = await floDapps.user.private;
|
||||||
@ -1065,38 +1076,41 @@
|
|||||||
|
|
||||||
//Pipelines
|
//Pipelines
|
||||||
const createPipeline = function(model, members, ekeySize = 16) {
|
const createPipeline = function(model, members, ekeySize = 16) {
|
||||||
//validate members
|
return new Promise((resolve, reject) => {
|
||||||
let imem1 = [],
|
//validate members
|
||||||
imem2 = []
|
let imem1 = [],
|
||||||
members.forEach(m =>
|
imem2 = []
|
||||||
!floCrypto.validateAddr(m) ? imem1.push(m) :
|
members.forEach(m =>
|
||||||
m in floGlobals.pubKeys ? null : imem2.push(m)
|
!floCrypto.validateAddr(m) ? imem1.push(m) :
|
||||||
);
|
m in floGlobals.pubKeys ? null :
|
||||||
if (imem1.length)
|
m != user.id ? imem2.push(m) : null
|
||||||
return reject(`Invalid Members(floIDs): ${imem1}`)
|
);
|
||||||
else if (imem2.length)
|
if (imem1.length)
|
||||||
return reject(`Invalid Members (pubKey not available): ${imem2}`)
|
return reject(`Invalid Members(floIDs): ${imem1}`);
|
||||||
//create pipeline info
|
else if (imem2.length)
|
||||||
const id = floCrypto.tmpID;
|
return reject(`Invalid Members (pubKey not available): ${imem2}`);
|
||||||
let pipeline = {
|
//create pipeline info
|
||||||
id,
|
const id = floCrypto.tmpID;
|
||||||
model,
|
let pipeline = {
|
||||||
members
|
id,
|
||||||
}
|
model,
|
||||||
if (ekeySize)
|
members
|
||||||
pipeline.eKey = floCrypto.randString(ekeySize);
|
}
|
||||||
//send pipeline info to members
|
if (ekeySize)
|
||||||
let pipelineInfo = JSON.stringify(pipeline);
|
pipeline.eKey = floCrypto.randString(ekeySize);
|
||||||
let promises = members.map(m => sendRaw(pipelineInfo, m, "CREATE_PIPELINE", true));
|
//send pipeline info to members
|
||||||
Promise.allSettled(promises).then(results => {
|
let pipelineInfo = JSON.stringify(pipeline);
|
||||||
console.debug(results.filter(r => r.status = "rejected").map(r => r.reason));
|
let promises = members.filter(m => m != user.id).map(m => sendRaw(pipelineInfo, m, "CREATE_PIPELINE", true));
|
||||||
_loaded.pipeline[pipeline.id] = Object.assign(pipeline, {});
|
Promise.allSettled(promises).then(results => {
|
||||||
if (pipeline.eKey)
|
console.debug(results.filter(r => r.status === "rejected").map(r => r.reason));
|
||||||
pipeline.eKey = encrypt(pipeline.eKey);
|
_loaded.pipeline[pipeline.id] = Object.assign({}, pipeline);
|
||||||
compactIDB.addData("pipeline", pipeline, pipeline.id).then(result => {
|
if (pipeline.eKey)
|
||||||
requestPipelineInbox(pipeline.id, pipeline.model);
|
pipeline.eKey = encrypt(pipeline.eKey);
|
||||||
resolve(_loaded.pipeline[pipeline.id])
|
compactIDB.addData("pipeline", pipeline, pipeline.id).then(result => {
|
||||||
}).catch(error => reject(error))
|
requestPipelineInbox(pipeline.id, pipeline.model);
|
||||||
|
resolve(_loaded.pipeline[pipeline.id])
|
||||||
|
}).catch(error => reject(error))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1119,7 +1133,7 @@
|
|||||||
continue;
|
continue;
|
||||||
try {
|
try {
|
||||||
parseData(dataSet[vc], newInbox);
|
parseData(dataSet[vc], newInbox);
|
||||||
if (data.sender !== user.id)
|
if (dataSet[vc].senderID !== user.id)
|
||||||
addMark(pipeID, "unread")
|
addMark(pipeID, "unread")
|
||||||
if (!_loaded.appendix[`lastReceived_${pipeID}`] ||
|
if (!_loaded.appendix[`lastReceived_${pipeID}`] ||
|
||||||
_loaded.appendix[`lastReceived_${pipeID}`] < vc)
|
_loaded.appendix[`lastReceived_${pipeID}`] < vc)
|
||||||
@ -1143,7 +1157,7 @@
|
|||||||
|
|
||||||
processData.pipeline = {};
|
processData.pipeline = {};
|
||||||
processData.pipeline[TYPE_BTC_MULTISIG] = function(pipeID) {
|
processData.pipeline[TYPE_BTC_MULTISIG] = function(pipeID) {
|
||||||
return (unparsed) => {
|
return (unparsed, newInbox) => {
|
||||||
if (!_loaded.pipeline[pipeID].members.includes(floCrypto.toFloID(unparsed.senderID)))
|
if (!_loaded.pipeline[pipeID].members.includes(floCrypto.toFloID(unparsed.senderID)))
|
||||||
return;
|
return;
|
||||||
let data = {
|
let data = {
|
||||||
@ -1151,7 +1165,8 @@
|
|||||||
sender: unparsed.senderID,
|
sender: unparsed.senderID,
|
||||||
pipeID: unparsed.receiverID
|
pipeID: unparsed.receiverID
|
||||||
}
|
}
|
||||||
let k = _loaded.pipeline[pipeID].eKey;
|
let vc = unparsed.vectorClock,
|
||||||
|
k = _loaded.pipeline[pipeID].eKey;
|
||||||
unparsed.message = decrypt(unparsed.message, k)
|
unparsed.message = decrypt(unparsed.message, k)
|
||||||
//store the pubKey if not stored already
|
//store the pubKey if not stored already
|
||||||
floDapps.storePubKey(unparsed.senderID, unparsed.pubKey);
|
floDapps.storePubKey(unparsed.senderID, unparsed.pubKey);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user