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() {
let data = {};
data.alias = normalizedAlias;
data.password = password;
- data.mnemonic = 'salon actor flag weasel potato afraid lyrics baby hero depth wage width';
- const res = createkey(data)
- console.log(res);
- // return createkey(data).then((res) => {
- // let jsonData = JSON.parse(res.data);
- // let dbData = {
- // key:res.data,
- // xpub:jsonData.xpub,
- // alias:alias,
- // };
- // return dbData;
- // }).catch(error => {
- // throw(error);
- // });
+ 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;
};
/**
let data = {};
data.alias = normalizedAlias;
data.auth = password;
- createKey(data).then((res) => {
+ createKey(data).then((res) => {
let jsonData = JSON.parse(res.data);
let dbData = {
key:res.data,