clean up extraneous variables and log statements

This commit is contained in:
ansuz 2018-07-17 14:34:25 +02:00
parent 8a18698c03
commit e6d4bced18
2 changed files with 11 additions and 36 deletions

View File

@ -48,9 +48,7 @@ define([
var edSeed = opt.edSeed = dispense(32); var edSeed = opt.edSeed = dispense(32);
// 64 more bytes to seed an additional signing key // 64 more bytes to seed an additional signing key
opt.blockSeed = new Uint8Array(dispense(64)); var blockKeys = opt.blockKeys = Block.genkeys(new Uint8Array(dispense(64)));
var blockKeys = opt.blockKeys = Block.genkeys(opt.blockSeed);
opt.blockHash = Block.getBlockHash(blockKeys); opt.blockHash = Block.getBlockHash(blockKeys);
// derive a private key from the ed seed // derive a private key from the ed seed
@ -87,13 +85,11 @@ define([
opt.channelHex = parsed.channel; opt.channelHex = parsed.channel;
opt.keys = parsed.keys; opt.keys = parsed.keys;
opt.edPublic = blockInfo.edPublic; opt.edPublic = blockInfo.edPublic;
opt.edPrivate = blockInfo.edPrivate;
opt.User_name = blockInfo.User_name; opt.User_name = blockInfo.User_name;
return opt; return opt;
}; };
var loadUserObject = function (opt, cb) { var loadUserObject = function (opt, cb) {
console.log(opt);
var config = { var config = {
websocketURL: NetConfig.getWebsocketURL(), websocketURL: NetConfig.getWebsocketURL(),
channel: opt.channelHex, channel: opt.channelHex,
@ -106,8 +102,6 @@ define([
owners: [opt.edPublic] owners: [opt.edPublic]
}; };
console.log(config);
var rt = opt.rt = Listmap.create(config); var rt = opt.rt = Listmap.create(config);
rt.proxy rt.proxy
.on('ready', function () { .on('ready', function () {
@ -281,7 +275,8 @@ define([
console.log("allocating random bytes for a new user object"); console.log("allocating random bytes for a new user object");
opt = allocateBytes(Nacl.randomBytes(Exports.requiredBytes)); opt = allocateBytes(Nacl.randomBytes(Exports.requiredBytes));
// create a random v2 hash, since we don't need backwards compatibility // create a random v2 hash, since we don't need backwards compatibility
userHash = '/drive/#' + Hash.createRandomHash('drive'); //userHash = opt.userHash = Hash.createRandomHash('drive'); // TODO
userHash = opt.userHash;
} }
// according to the location derived from the credentials which you entered // according to the location derived from the credentials which you entered
@ -394,7 +389,6 @@ define([
toPublish[Constants.userNameKey] = uname; toPublish[Constants.userNameKey] = uname;
toPublish[Constants.userHashKey] = userHash; toPublish[Constants.userHashKey] = userHash;
toPublish.edPublic = RT.proxy.edPublic; toPublish.edPublic = RT.proxy.edPublic;
toPublish.edPrivate = RT.proxy.edPrivate;
var blockRequest = Block.serialize(JSON.stringify(toPublish), res.opt.blockKeys); var blockRequest = Block.serialize(JSON.stringify(toPublish), res.opt.blockKeys);

View File

@ -716,7 +716,7 @@ define([
var password = data.password; // To remove your old block var password = data.password; // To remove your old block
var newPassword = data.newPassword; // To create your new block var newPassword = data.newPassword; // To create your new block
var secret = Hash.getSecrets('drive', hash); var secret = Hash.getSecrets('drive', hash);
var newHash, newHref, newSecret, newBlockSeed; var newHash, newHref, newSecret, blockKeys;
var oldIsOwned = false; var oldIsOwned = false;
var blockHash = LocalStore.getBlockHash(); var blockHash = LocalStore.getBlockHash();
@ -724,7 +724,6 @@ define([
var Cred, Block, Login; var Cred, Block, Login;
Nthen(function (waitFor) { Nthen(function (waitFor) {
console.log("loading necessary modules");
require([ require([
'/customize/credential.js', '/customize/credential.js',
'/common/outer/login-block.js', '/common/outer/login-block.js',
@ -736,13 +735,12 @@ define([
})); }));
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
// confirm that the provided password is correct // confirm that the provided password is correct
console.log("checking whether the password you entered was correct");
Cred.deriveFromPassphrase(accountName, password, Login.requiredBytes, waitFor(function (bytes) { Cred.deriveFromPassphrase(accountName, password, Login.requiredBytes, waitFor(function (bytes) {
var allocated = Login.allocateBytes(bytes); var allocated = Login.allocateBytes(bytes);
oldBlockKeys = allocated.blockKeys; oldBlockKeys = allocated.blockKeys;
if (blockHash) { if (blockHash) {
if (blockHash !== allocated.blockHash) { if (blockHash !== allocated.blockHash) {
console.log("password did not yield the correct blockHash ?"); console.log("provided password did not yield the correct blockHash");
// incorrect password probably // incorrect password probably
waitFor.abort(); waitFor.abort();
return void cb({ return void cb({
@ -753,7 +751,7 @@ define([
} else { } else {
// otherwise they're a legacy user, and we should check against the User_hash // otherwise they're a legacy user, and we should check against the User_hash
if (hash !== allocated.userHash) { if (hash !== allocated.userHash) {
console.log("password did not yield the correct userHash"); console.log("provided password did not yield the correct userHash");
waitFor.abort(); waitFor.abort();
return void cb({ return void cb({
error: 'INVALID_PASSWORD', error: 'INVALID_PASSWORD',
@ -791,26 +789,12 @@ define([
return void cb({ error: err }); return void cb({ error: err });
} }
console.log(val);
console.log("%s => %s", hash, newHash);
Crypt.put(newHash, val, waitFor(function (err) { Crypt.put(newHash, val, waitFor(function (err) {
if (err) { if (err) {
waitFor.abort(); waitFor.abort();
console.error(err); console.error(err);
return void cb({ error: err }); return void cb({ error: err });
} }
console.error('checking content at newHash: %s', newHash);
Crypt.get(newHash, function (err, val) {
if (err) {
waitFor.abort();
console.log(err);
return void cb({ error: err });
}
console.error(val);
});
}), optsPut); }), optsPut);
})); }));
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
@ -818,30 +802,27 @@ define([
console.log("deriving new credentials from passphrase"); console.log("deriving new credentials from passphrase");
Cred.deriveFromPassphrase(accountName, newPassword, Login.requiredBytes, waitFor(function (bytes) { Cred.deriveFromPassphrase(accountName, newPassword, Login.requiredBytes, waitFor(function (bytes) {
var allocated = Login.allocateBytes(bytes); var allocated = Login.allocateBytes(bytes);
newBlockSeed = allocated.blockSeed; blockKeys = allocated.blockKeys;
})); }));
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
// Write the new login block // Write the new login block
var keys = Block.genkeys(newBlockSeed);
var temp = { var temp = {
User_name: accountName, User_name: accountName,
User_hash: newHash, User_hash: newHash,
edPublic: edPublic, edPublic: edPublic,
// edPrivate XXX
}; };
var content = Block.serialize(JSON.stringify(temp), keys); var content = Block.serialize(JSON.stringify(temp), blockKeys);
console.log("writing new login block"); console.log("writing new login block");
common.writeLoginBlock(content, waitFor(function (obj) { common.writeLoginBlock(content, waitFor(function (obj) {
console.log("new login block written");
var newBlockHash = Block.getBlockHash(keys);
LocalStore.setBlockHash(newBlockHash);
if (obj && obj.error) { if (obj && obj.error) {
waitFor.abort(); waitFor.abort();
return void cb(obj); return void cb(obj);
} }
console.log("new login block written");
var newBlockHash = Block.getBlockHash(blockKeys);
LocalStore.setBlockHash(newBlockHash);
})); }));
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
// New drive hash is in login block, unpin the old one and pin the new one // New drive hash is in login block, unpin the old one and pin the new one