add wallet import test
This commit is contained in:
parent
5a3134212c
commit
89ec5ad61e
4 changed files with 75 additions and 74 deletions
|
|
@ -15,14 +15,12 @@ Passphrase.prototype.get = function(password) {
|
|||
keySize: 512 / 32,
|
||||
iterations: this.iterations
|
||||
});
|
||||
|
||||
return key512;
|
||||
};
|
||||
|
||||
Passphrase.prototype.getBase64 = function(password) {
|
||||
var key512 = this.get(password);
|
||||
var keyBase64 = key512.toString(CryptoJS.enc.Base64);
|
||||
|
||||
return keyBase64;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ var TxProposals = require('./TxProposals');
|
|||
var PublicKeyRing = require('./PublicKeyRing');
|
||||
var PrivateKey = require('./PrivateKey');
|
||||
var Wallet = require('./Wallet');
|
||||
var preconditions = require('preconditions').instance();
|
||||
|
||||
var log = require('../../log');
|
||||
|
||||
|
|
@ -13,7 +14,6 @@ var StorageLocalEncrypted = module.exports.StorageLocalEncrypted = require('../s
|
|||
|
||||
/*
|
||||
* WalletFactory
|
||||
*
|
||||
*/
|
||||
|
||||
function WalletFactory(config, version) {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
var CryptoJS = require('node-cryptojs-aes').CryptoJS;
|
||||
var bitcore = require('bitcore');
|
||||
var preconditions = require('preconditions').instance();
|
||||
var id = 0;
|
||||
|
||||
function Storage(opts) {
|
||||
|
|
@ -11,15 +12,12 @@ function Storage(opts) {
|
|||
if (opts.password)
|
||||
this._setPassphrase(opts.password);
|
||||
|
||||
try{
|
||||
try {
|
||||
this.localStorage = opts.localStorage || localStorage;
|
||||
this.sessionStorage = opts.sessionStorage || sessionStorage;
|
||||
} catch (e) {};
|
||||
|
||||
if (!this.localStorage)
|
||||
throw new Error('no localStorage');
|
||||
if (!this.sessionStorage)
|
||||
throw new Error('no sessionStorage');
|
||||
} catch (e) {}
|
||||
preconditions.checkState(this.localStorage, 'No localstorage found');
|
||||
preconditions.checkState(this.sessionStorage, 'No sessionStorage found');
|
||||
}
|
||||
|
||||
var pps = {};
|
||||
|
|
@ -40,11 +38,6 @@ Storage.prototype._encrypt = function(string) {
|
|||
return encryptedBase64;
|
||||
};
|
||||
|
||||
Storage.prototype._encryptObj = function(obj) {
|
||||
var string = JSON.stringify(obj);
|
||||
return this._encrypt(string);
|
||||
};
|
||||
|
||||
Storage.prototype._decrypt = function(base64) {
|
||||
var decryptedStr = null;
|
||||
try {
|
||||
|
|
@ -58,10 +51,6 @@ Storage.prototype._decrypt = function(base64) {
|
|||
return decryptedStr;
|
||||
};
|
||||
|
||||
Storage.prototype._decryptObj = function(base64) {
|
||||
var decryptedStr = this._decrypt(base64);
|
||||
return JSON.parse(decryptedStr);
|
||||
};
|
||||
|
||||
Storage.prototype._read = function(k) {
|
||||
var ret;
|
||||
|
|
@ -98,7 +87,7 @@ Storage.prototype.removeGlobal = function(k) {
|
|||
};
|
||||
|
||||
Storage.prototype.getSessionId = function() {
|
||||
var sessionId = this.sessionStorage.getItem('sessionId');
|
||||
var sessionId = this.sessionStorage.getItem('sessionId');
|
||||
if (!sessionId) {
|
||||
sessionId = bitcore.SecureRandom.getRandomBuffer(8).toString('hex');
|
||||
this.sessionStorage.setItem('sessionId', sessionId);
|
||||
|
|
@ -131,7 +120,6 @@ Storage.prototype.setName = function(walletId, name) {
|
|||
|
||||
Storage.prototype.getName = function(walletId) {
|
||||
var ret = this.getGlobal('nameFor::' + walletId);
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
|
@ -145,7 +133,7 @@ Storage.prototype.getWalletIds = function() {
|
|||
if (split.length == 2) {
|
||||
var walletId = split[0];
|
||||
|
||||
if (!walletId || walletId === 'nameFor' || walletId ==='lock')
|
||||
if (!walletId || walletId === 'nameFor' || walletId === 'lock')
|
||||
continue;
|
||||
|
||||
if (typeof uniq[walletId] === 'undefined') {
|
||||
|
|
@ -207,14 +195,14 @@ Storage.prototype.clearAll = function() {
|
|||
this.localStorage.clear();
|
||||
};
|
||||
|
||||
Storage.prototype.export = function(obj) {
|
||||
var encryptedObj = this._encryptObj(obj);
|
||||
return encryptedObj;
|
||||
Storage.prototype.import = function(base64) {
|
||||
var decryptedStr = this._decrypt(base64);
|
||||
return JSON.parse(decryptedStr);
|
||||
};
|
||||
|
||||
Storage.prototype.import = function(base64) {
|
||||
var decryptedObj = this._decryptObj(base64);
|
||||
return decryptedObj;
|
||||
Storage.prototype.export = function(obj) {
|
||||
var string = JSON.stringify(obj);
|
||||
return this._encrypt(string);
|
||||
};
|
||||
|
||||
module.exports = Storage;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue