-import {createKey, resetKeyPassword, createPubkey, signMessage, signTransaction} from '../wasm/func';
+import { createKey ,resetKeyPassword, createPubkey, signMessage, signTransaction} from '../wasm/func';
import {getDB} from '../db/db';
+import {createkey} from '../utils/key/createKey';
+import {encryptKey, decryptKey} from '../utils/key/keystore';
+import { restoreFromKeyStore } from '../utils/account';
function keysSDK() {
/**
* Create a new key.
+ *
+ * @param {String} alias - User specified, unique identifier.
+ * @param {String} password - User specified, key password.
+ */
+keysSDK.prototype.createKey = function(alias, password) {
+ var normalizedAlias = alias.toLowerCase().trim();
+
+ let data = {};
+ data.alias = normalizedAlias;
+ data.password = password;
+ const res = createkey(data);
+ return res;
+};
+
+/**
+ * Create a new key.
+ *
+ * @param {String} alias - User specified, unique identifier.
+ * @param {String} password - User specified, key password.
+ */
+keysSDK.prototype.restoreFromMnemonic = function(alias, password, mnemonic) {
+ var normalizedAlias = alias.toLowerCase().trim();
+
+ let data = {};
+ data.alias = normalizedAlias;
+ data.password = password;
+ data.mnemonic = mnemonic;
+
+ const res = createkey(data);
+
+ const xpub = res.xpub;
+
+ //Todo: /account/wallets api find if xpub exist in the blockcenter, yes restore, otherwise create new account
+
+ return res;
+};
+
+/**
+ * Create a new key.
*
* @param {String} alias - User specified, unique identifier.
* @param {String} password - User specified, key password.
getDB().then(db => {
let getRequest = db.transaction(['accounts-server'], 'readonly')
.objectStore('accounts-server')
- .getAll()
+ .getAll();
getRequest.onsuccess = function (e) {
- const result = getRequest.result.filter(obj => obj.address === address)
+ const result = getRequest.result.filter(obj => (obj.address === address || obj.vpAddress === address));
if (result.length === 0) {
reject(new Error('not found address'));
return;
}
- const rootXpub = result[0].rootXPub
+ const rootXpub = result[0].rootXPub;
let keyObject = db.transaction(['keys'], 'readonly')
.objectStore('keys')
.index('xpub')