|
|
|
@ -112,7 +112,7 @@ var validateAncestorProof = function (Env, proof, _cb) {
|
|
|
|
|
return void cb("E_MISSING_ANCESTOR");
|
|
|
|
|
}));
|
|
|
|
|
}).nThen(function () {
|
|
|
|
|
cb(void 0, valid);
|
|
|
|
|
cb(void 0, pub);
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
return void cb(err);
|
|
|
|
@ -126,6 +126,7 @@ Block.writeLoginBlock = function (Env, safeKey, msg, _cb) { // FIXME BLOCKS
|
|
|
|
|
var signature = msg[1];
|
|
|
|
|
var block = msg[2];
|
|
|
|
|
var registrationProof = msg[3];
|
|
|
|
|
var previousKey;
|
|
|
|
|
|
|
|
|
|
var validatedBlock, parsed, path;
|
|
|
|
|
nThen(function (w) {
|
|
|
|
@ -136,13 +137,15 @@ Block.writeLoginBlock = function (Env, safeKey, msg, _cb) { // FIXME BLOCKS
|
|
|
|
|
w.abort();
|
|
|
|
|
return cb("E_RESTRICTED");
|
|
|
|
|
}
|
|
|
|
|
validateAncestorProof(Env, registrationProof, w(function (err, validated) {
|
|
|
|
|
if (err || !validated) { // double check that it was validated
|
|
|
|
|
validateAncestorProof(Env, registrationProof, w(function (err, provenKey) {
|
|
|
|
|
if (err || !provenKey) { // double check that a key was validated
|
|
|
|
|
w.abort();
|
|
|
|
|
// XXX Log
|
|
|
|
|
return void cb("E_RESTRICTED"); // XXX restricted-registration we can provide more descriptive errors if we check that the client will understand them
|
|
|
|
|
Env.Log.warn('BLOCK_REJECTED_INVALID_ANCESTOR', {
|
|
|
|
|
error: err,
|
|
|
|
|
});
|
|
|
|
|
return void cb("E_RESTRICTED");
|
|
|
|
|
}
|
|
|
|
|
// else fall through to the next block
|
|
|
|
|
previousKey = provenKey;
|
|
|
|
|
}));
|
|
|
|
|
}).nThen(function (w) {
|
|
|
|
|
validateLoginBlock(Env, publicKey, signature, block, w(function (e, _validatedBlock) {
|
|
|
|
@ -183,7 +186,12 @@ Block.writeLoginBlock = function (Env, safeKey, msg, _cb) { // FIXME BLOCKS
|
|
|
|
|
// actually write the block
|
|
|
|
|
Fs.writeFile(path, Buffer.from(validatedBlock), { encoding: "binary", }, function (err) {
|
|
|
|
|
if (err) { return void cb(err); }
|
|
|
|
|
// XXX log the safeKey to map publicKey <=> block
|
|
|
|
|
Env.Log.info('BLOCK_WRITE_BY_OWNER', {
|
|
|
|
|
safeKey: safeKey,
|
|
|
|
|
blockId: publicKey,
|
|
|
|
|
isChange: Boolean(registrationProof),
|
|
|
|
|
previousKey: previousKey,
|
|
|
|
|
});
|
|
|
|
|
cb();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|