import bytom from './bytom'
import uuid from 'uuid'
-import address from "../utils/address";
+import * as Actions from '../store/constants';
let account = {
setupNet: bytom.setupNet
}
-account.create = function(accountAlias, keyAlias, passwd, success, error) {
+account.create = function(accountAlias, keyAlias, passwd, context) {
let retPromise = new Promise((resolve, reject) => {
if(!keyAlias){
keyAlias = `${accountAlias}-key-${uuid.v4()}`
}
+
+ const _bytom = context.bytom.clone();
bytom.keys
- .create(keyAlias, passwd)
+ .createKey(keyAlias, passwd)
.then(res => {
- bytom.accounts
- .createAccountUseServer(res.xpub, accountAlias)
- .then(ret => {
- resolve(ret)
+ _bytom.keychain.keys[keyAlias] = res
+ context[Actions.UPDATE_STORED_BYTOM](_bytom).then(() => {
+ bytom.accounts
+ .createAccountUseServer(res.xpub, accountAlias)
+ .then(ret => {
+ resolve(ret)
+ })
+ .catch(error => {
+ reject(error)
+ })
})
.catch(error => {
reject(error)
})
- })
- .catch(error => {
- reject(error)
- })
+
+ });
+
})
return retPromise
}
return retPromise;
};
-transaction.signTransaction = function(guid, transaction, password) {
+transaction.signTransaction = function(guid, transaction, password, context) {
let retPromise = new Promise((resolve, reject) => {
- bytom.transaction
- .signTransaction(guid, JSON.stringify(snakeize(transaction)), password)
+ signTx(
+ guid,
+ JSON.stringify(snakeize(transaction)),
+ password,
+ context
+ )
.then(res => {
resolve(res);
})
return retPromise;
};
-transaction.transfer = function(guid, transaction, password, address) {
+transaction.transfer = function(guid, transaction, password, address, context) {
let retPromise = new Promise((resolve, reject) => {
- bytom.transaction
- .signTransaction(guid, JSON.stringify(snakeize(transaction)), password)
+ signTx(
+ guid,
+ JSON.stringify(snakeize(transaction)),
+ password,
+ context
+ )
.then(ret => {
bytom.transaction
.submitPayment(address, ret.raw_transaction, ret.signatures)
return bytom.keys.signMessage(message, password,address);
};
-transaction.advancedTransfer = function(guid, transaction, password, arrayData, address) {
+transaction.advancedTransfer = function(guid, transaction, password, arrayData, address, context) {
let retPromise = new Promise((resolve, reject) => {
- bytom.transaction
- .signTransaction(guid, JSON.stringify(snakeize(transaction)), password)
+ signTx(
+ guid,
+ JSON.stringify(snakeize(transaction)),
+ password,
+ context
+ )
.then(ret => {
let signatures = ret.signatures
if(arrayData){
return retPromise;
};
+
+
+function signTx(guid, transaction, password, context){
+ return bytom.accounts.getAccountXpub(guid).then((xpub)=>{
+ const keyArray = context.bytom.keychain.findIdentity(xpub);
+ if(!keyArray){
+ throw 'xpub not found'
+ }else{
+ const key = keyArray.key
+ return bytom.transaction
+ ._signTransaction(
+ transaction,
+ password,
+ key
+ )
+ }
+ })
+}
+
export default transaction;
language:state => state.bytom.settings.language,
login:state => state.bytom.settings.login,
currency:state => state.bytom.settings.currency,
+ keys: state => state.bytom.keychain.keys,
// FOR PROMPTS ONLY
messages:state => state.prompt.data.messages || [],
import Settings from './Settings';
+import Keychain from './Keychain';
export default class BytomObj {
constructor(){
this.settings = Settings.placeholder();
+ this.keychain = Keychain.placeholder();
+ this.histories = [];
}
static placeholder(){ return new BytomObj(); }
static fromJson(json){
let p = Object.assign(this.placeholder(), json);
if(json.hasOwnProperty('settings')) p.settings = Settings.fromJson(json.settings);
+ if(json.hasOwnProperty('keychain'))
+ p.keychain = (typeof json.keychain === 'string')
+ ? json.keychain : Keychain.fromJson(json.keychain);
+
return p;
}
--- /dev/null
+export default class Keychain {
+
+ constructor(){
+ this.keys = {};
+ }
+
+ static placeholder(){ return new Keychain(); }
+ static fromJson(json){
+ let p = Object.assign(this.placeholder(), json);
+ if(json.hasOwnProperty('keys')) p.keys = json.keys;
+ return p;
+ }
+
+ findIdentity(publicKey){ return Object.values(this.keys).find(id => id.xpub === publicKey); }
+}
import modalPasswd from "@/components/modal-passwd";
import getLang from "@/assets/language/sdk";
import { LocalStream } from 'extension-streams';
-import { mapGetters } from 'vuex'
+import { mapGetters , mapState} from 'vuex'
export default {
components: {
return Number(this.transaction.amount)
}
},
+ ...mapState([
+ 'bytom'
+ ]),
...mapGetters([
'language',
'net',
address = this.netType === 'vapor'? this.account.vpAddress: this.account.address;
}
- Promise.all(this.rawData.map( (rawdata) => transaction.transfer(this.account.guid, rawdata, this.password, address)))
+ Promise.all(this.rawData.map( (rawdata) => transaction.transfer(this.account.guid, rawdata, this.password, address, this)))
.then(ret => {
loader.hide();
if(this.$route.params.type == 'popup'){
account.setupNet(`${this.net}`);
if(this.netType === 'vapor'){
- account.create(this.formItem.accAlias, null, this.formItem.passwd1).then((resp) => {
+ account.create(this.formItem.accAlias, null, this.formItem.passwd1, this).then((resp) => {
account.setupNet(`${this.net}vapor`);
return account.copy(resp.guid).then((currentRespAccount)=>{
this[Actions.CREATE_NEW_BYTOM_ACCOUNT](currentRespAccount).then(()=>{
});
});
}else{
- account.create(this.formItem.accAlias, null, this.formItem.passwd1).then(account => {
+ account.create(this.formItem.accAlias, null, this.formItem.passwd1,this).then(account => {
this[Actions.CREATE_NEW_BYTOM_ACCOUNT](account).then(()=>{
loader.hide();
this.$router.push('/');
},
...mapActions([
Actions.CREATE_NEW_BYTOM_ACCOUNT,
+ Actions.UPDATE_STORED_BYTOM
])
},
mounted() { }
canCancel: true,
onCancel: this.onCancel
});
- account.create(this.formItem.accAlias, null, this.formItem.passwd1).then(currentAccount => {
+ account.create(this.formItem.accAlias, null, this.formItem.passwd1, this).then(currentAccount => {
this[Actions.CREATE_NEW_BYTOM](this.selected.value).then(() =>{
loader.hide();
this.formItem = {};
...mapActions([
Actions.CREATE_NEW_BYTOM,
Actions.IMPORT_BYTOM,
+ Actions.UPDATE_STORED_BYTOM
])
},
watch: {