Add method post encrypt auth data

This commit is contained in:
DwCay
2022-06-29 18:47:49 +03:00
parent 1d9368d200
commit 63439b2da1
2 changed files with 23 additions and 4 deletions

View File

@@ -21,6 +21,14 @@ class Store {
}))
};
postAuth() {
fetchWrapper.postAuth('http://3.125.47.101/api/data/account', {
networkIdentifier: this.nodeInfo.networkIdentifier,
lastBlockID: this.nodeInfo.lastBlockID
}, [...this.encryptAccountData])
.then((result) => console.log(result))
}
savePassPhrase(phrase) {
this._passPhrase = phrase
}
@@ -37,7 +45,6 @@ class Store {
fetchNodeInfoSuccess(info) {
this._nodeInfo = info.data;
console.log(info)
}
fetchNodeInfoFailed(err) {
@@ -52,6 +59,17 @@ class Store {
return this._accountData
};
get encryptAccountData() {
return Object.keys(this.accountData).map((label) => {
let value = cryptography.encryptMessageWithPassphrase(cryptography.getRandomBytes(32).toString('hex') + ":" + this.accountData[label], this.passPhrase, this.pubKey);
return {
"label": label,
"value": value.encryptedMessage,
"value_nonce": value.nonce,
}
})
}
get nodeInfo() {
return this._nodeInfo;
}
@@ -69,7 +87,7 @@ class Store {
}
get tokenKey() {
const stringToSign = this.nodeInfo.networkIdentifier.concat(this.nodeInfo.lastBlockID);
const stringToSign = this.nodeInfo.networkIdentifier + this.nodeInfo.lastBlockID;
if(!stringToSign)
return '';
const sign = cryptography.signDataWithPassphrase(Buffer.from(stringToSign, 'hex'), this.passPhrase).toString('hex')