|
|
|
@ -232,17 +232,6 @@ define([
|
|
|
|
|
};
|
|
|
|
|
postMessage("MIGRATE_ANON_DRIVE", data, cb);
|
|
|
|
|
};
|
|
|
|
|
// Settings
|
|
|
|
|
common.deleteAccount = function (cb) {
|
|
|
|
|
postMessage("DELETE_ACCOUNT", null, function (obj) {
|
|
|
|
|
if (obj.state) {
|
|
|
|
|
Feedback.send('DELETE_ACCOUNT_AUTOMATIC');
|
|
|
|
|
} else {
|
|
|
|
|
Feedback.send('DELETE_ACCOUNT_MANUAL');
|
|
|
|
|
}
|
|
|
|
|
cb(obj);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
// Drive
|
|
|
|
|
common.userObjectCommand = function (data, cb) {
|
|
|
|
|
postMessage("DRIVE_USEROBJECT", data, cb);
|
|
|
|
@ -1674,30 +1663,16 @@ define([
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
common.changeUserPassword = function (Crypt, edPublic, data, cb) {
|
|
|
|
|
if (!edPublic) {
|
|
|
|
|
return void cb({
|
|
|
|
|
error: 'E_NOT_LOGGED_IN'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
var getBlockKeys = function (data, cb) {
|
|
|
|
|
var accountName = LocalStore.getAccountName();
|
|
|
|
|
var hash = LocalStore.getUserHash();
|
|
|
|
|
if (!hash) {
|
|
|
|
|
return void cb({
|
|
|
|
|
error: 'E_NOT_LOGGED_IN'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var password = data.password; // To remove your old block
|
|
|
|
|
var newPassword = data.newPassword; // To create your new block
|
|
|
|
|
var secret = Hash.getSecrets('drive', hash);
|
|
|
|
|
var newHash, newHref, newSecret, blockKeys;
|
|
|
|
|
var oldIsOwned = false;
|
|
|
|
|
var password = data.password;
|
|
|
|
|
var Cred, Block, Login;
|
|
|
|
|
var blockKeys;
|
|
|
|
|
|
|
|
|
|
var hash = LocalStore.getUserHash();
|
|
|
|
|
if (!hash) { return void cb({ error: 'E_NOT_LOGGED_IN' }); }
|
|
|
|
|
var blockHash = LocalStore.getBlockHash();
|
|
|
|
|
var oldBlockKeys;
|
|
|
|
|
|
|
|
|
|
var Cred, Block, Login;
|
|
|
|
|
Nthen(function (waitFor) {
|
|
|
|
|
require([
|
|
|
|
|
'/common/common-credential.js',
|
|
|
|
@ -1710,30 +1685,92 @@ define([
|
|
|
|
|
}));
|
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
|
// confirm that the provided password is correct
|
|
|
|
|
Cred.deriveFromPassphrase(accountName, password, Login.requiredBytes, waitFor(function (bytes) {
|
|
|
|
|
Cred.deriveFromPassphrase(accountName, password, Login.requiredBytes,
|
|
|
|
|
waitFor(function (bytes) {
|
|
|
|
|
var allocated = Login.allocateBytes(bytes);
|
|
|
|
|
oldBlockKeys = allocated.blockKeys;
|
|
|
|
|
blockKeys = allocated.blockKeys;
|
|
|
|
|
if (blockHash) {
|
|
|
|
|
if (blockHash !== allocated.blockHash) {
|
|
|
|
|
// incorrect password
|
|
|
|
|
console.log("provided password did not yield the correct blockHash");
|
|
|
|
|
// incorrect password probably
|
|
|
|
|
waitFor.abort();
|
|
|
|
|
return void cb({
|
|
|
|
|
error: 'INVALID_PASSWORD',
|
|
|
|
|
});
|
|
|
|
|
return void cb({ error: 'INVALID_PASSWORD', });
|
|
|
|
|
}
|
|
|
|
|
// the user has already created a block, so you should compare against that
|
|
|
|
|
} else {
|
|
|
|
|
// otherwise they're a legacy user, and we should check against the User_hash
|
|
|
|
|
if (hash !== allocated.userHash) {
|
|
|
|
|
// incorrect password
|
|
|
|
|
console.log("provided password did not yield the correct userHash");
|
|
|
|
|
waitFor.abort();
|
|
|
|
|
return void cb({
|
|
|
|
|
error: 'INVALID_PASSWORD',
|
|
|
|
|
});
|
|
|
|
|
return void cb({ error: 'INVALID_PASSWORD', });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
}).nThen(function () {
|
|
|
|
|
cb({
|
|
|
|
|
Cred: Cred,
|
|
|
|
|
Block: Block,
|
|
|
|
|
Login: Login,
|
|
|
|
|
blockKeys: blockKeys
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
common.deleteAccount = function (data, cb) {
|
|
|
|
|
data = data || {};
|
|
|
|
|
|
|
|
|
|
// Confirm that the provided password is corrct and get the block keys
|
|
|
|
|
getBlockKeys(data, function (obj) {
|
|
|
|
|
if (obj && obj.error) { return void cb(obj); }
|
|
|
|
|
var blockKeys = obj.blockKeys;
|
|
|
|
|
var removeData = obj.Block.remove(blockKeys);
|
|
|
|
|
|
|
|
|
|
postMessage("DELETE_ACCOUNT", {
|
|
|
|
|
removeData: removeData
|
|
|
|
|
}, function (obj) {
|
|
|
|
|
if (obj.state) {
|
|
|
|
|
Feedback.send('DELETE_ACCOUNT_AUTOMATIC');
|
|
|
|
|
} else {
|
|
|
|
|
Feedback.send('DELETE_ACCOUNT_MANUAL');
|
|
|
|
|
}
|
|
|
|
|
cb(obj);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
common.changeUserPassword = function (Crypt, edPublic, data, cb) {
|
|
|
|
|
if (!edPublic) {
|
|
|
|
|
return void cb({
|
|
|
|
|
error: 'E_NOT_LOGGED_IN'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
var accountName = LocalStore.getAccountName();
|
|
|
|
|
var hash = LocalStore.getUserHash();
|
|
|
|
|
if (!hash) {
|
|
|
|
|
return void cb({
|
|
|
|
|
error: 'E_NOT_LOGGED_IN'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var password = data.password; // To remove your old block
|
|
|
|
|
var newPassword = data.newPassword; // To create your new block
|
|
|
|
|
var secret = Hash.getSecrets('drive', hash);
|
|
|
|
|
var newHash, newHref, newSecret, blockKeys;
|
|
|
|
|
var oldIsOwned = false;
|
|
|
|
|
|
|
|
|
|
var blockHash = LocalStore.getBlockHash();
|
|
|
|
|
var oldBlockKeys;
|
|
|
|
|
|
|
|
|
|
var Cred, Block, Login;
|
|
|
|
|
Nthen(function (waitFor) {
|
|
|
|
|
getBlockKeys(data, waitFor(function (obj) {
|
|
|
|
|
if (obj && obj.error) {
|
|
|
|
|
waitFor.abort();
|
|
|
|
|
return void cb(obj);
|
|
|
|
|
}
|
|
|
|
|
oldBlockKeys = obj.blockKeys;
|
|
|
|
|
Cred = obj.Cred;
|
|
|
|
|
Login = obj.Login;
|
|
|
|
|
Block = obj.Block;
|
|
|
|
|
}));
|
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
|
// Check if our drive is already owned
|
|
|
|
|
console.log("checking if old drive is owned");
|
|
|
|
|