auth
This commit is contained in:
@@ -1,41 +0,0 @@
|
||||
import { reaction, makeAutoObservable } from "mobx";
|
||||
import {cryptography} from "@liskhq/lisk-client";
|
||||
|
||||
class RegistrationStore {
|
||||
_accountData = {}
|
||||
|
||||
_passPhraseStore=''
|
||||
|
||||
_pubKey = ''
|
||||
|
||||
constructor() {
|
||||
makeAutoObservable(this);
|
||||
reaction(()=>this.passPhraseStore, ()=>this.savePubKey())
|
||||
};
|
||||
|
||||
savePassPhrase(phrase) {
|
||||
this._passPhraseStore = phrase
|
||||
}
|
||||
|
||||
saveDataRegistration(data) {
|
||||
this._accountData = data;
|
||||
};
|
||||
savePubKey() {
|
||||
this._pubKey = cryptography.bufferToHex(cryptography.getAddressAndPublicKeyFromPassphrase(this.passPhraseStore).publicKey)
|
||||
}
|
||||
|
||||
get passPhraseStore() {
|
||||
return this._passPhraseStore
|
||||
}
|
||||
|
||||
get accountData() {
|
||||
return this._accountData
|
||||
};
|
||||
|
||||
get pubKey() {
|
||||
return this._pubKey
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
export const registrationStore = new RegistrationStore();
|
||||
81
src/store/store.js
Normal file
81
src/store/store.js
Normal file
@@ -0,0 +1,81 @@
|
||||
import { reaction, makeAutoObservable } from "mobx";
|
||||
import {cryptography} from "@liskhq/lisk-client";
|
||||
import {getNodeInfo} from '../api/node';
|
||||
import {fetchWrapper} from '../shared/fetchWrapper';
|
||||
|
||||
class Store {
|
||||
_accountData = {}
|
||||
|
||||
_passPhrase='rocket north inform swift improve fringe sweet crew client canyon bean autumn'
|
||||
|
||||
_nodeInfo = {}
|
||||
|
||||
constructor() {
|
||||
makeAutoObservable(this);
|
||||
|
||||
this.fetchNodeInfo()
|
||||
|
||||
reaction(() => this.tokenKey, () => fetchWrapper.getAuth('http://3.125.47.101/api/data/account', {
|
||||
networkIdentifier: this.nodeInfo.networkIdentifier,
|
||||
lastBlockID: this.nodeInfo.lastBlockID
|
||||
}))
|
||||
};
|
||||
|
||||
savePassPhrase(phrase) {
|
||||
this._passPhrase = phrase
|
||||
}
|
||||
|
||||
saveDataRegistration(data) {
|
||||
this._accountData = data;
|
||||
};
|
||||
|
||||
fetchNodeInfo() {
|
||||
getNodeInfo()
|
||||
.then((info) => this.fetchNodeInfoSuccess(info))
|
||||
.catch((err) => this.fetchNodeInfoFailed(err))
|
||||
}
|
||||
|
||||
fetchNodeInfoSuccess(info) {
|
||||
this._nodeInfo = info.data;
|
||||
console.log(info)
|
||||
}
|
||||
|
||||
fetchNodeInfoFailed(err) {
|
||||
console.log(err)
|
||||
}
|
||||
|
||||
get passPhrase() {
|
||||
return 'rocket north inform swift improve fringe sweet crew client canyon bean autumn'
|
||||
}
|
||||
|
||||
get accountData() {
|
||||
return this._accountData
|
||||
};
|
||||
|
||||
get nodeInfo() {
|
||||
return this._nodeInfo;
|
||||
}
|
||||
|
||||
get addressAndPubKey() {
|
||||
return cryptography.getAddressAndPublicKeyFromPassphrase(this.passPhrase);
|
||||
}
|
||||
|
||||
get pubKey() {
|
||||
return this.addressAndPubKey.publicKey.toString('hex');
|
||||
}
|
||||
|
||||
get address() {
|
||||
return cryptography.bufferToHex(this.addressAndPubKey.address)
|
||||
}
|
||||
|
||||
get tokenKey() {
|
||||
const stringToSign = this.nodeInfo.networkIdentifier.concat(this.nodeInfo.lastBlockID);
|
||||
if(!stringToSign)
|
||||
return '';
|
||||
const sign = cryptography.signDataWithPassphrase(Buffer.from(stringToSign, 'hex'), this.passPhrase).toString('hex')
|
||||
return this.pubKey + ':' +sign
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
export const registrationStore = new Store();
|
||||
Reference in New Issue
Block a user