validate data
This commit is contained in:
@@ -8,6 +8,7 @@ import SharedDataRoadMap from "../partials/sharedData/SharedDataRoadmap";
|
|||||||
import { store } from "../store/store";
|
import { store } from "../store/store";
|
||||||
import { fetchWrapper } from "../shared/fetchWrapper";
|
import { fetchWrapper } from "../shared/fetchWrapper";
|
||||||
import { cryptography } from "@liskhq/lisk-client";
|
import { cryptography } from "@liskhq/lisk-client";
|
||||||
|
import {generateTransaction} from '../utils/Utils';
|
||||||
|
|
||||||
function SharedData() {
|
function SharedData() {
|
||||||
const [encryptedData, setEncryptedData] = useState([]);
|
const [encryptedData, setEncryptedData] = useState([]);
|
||||||
@@ -35,7 +36,7 @@ function SharedData() {
|
|||||||
item.value,
|
item.value,
|
||||||
item.value_nonce,
|
item.value_nonce,
|
||||||
passPhrase,
|
passPhrase,
|
||||||
pubKey
|
Buffer.from(pubKey, 'hex')
|
||||||
)
|
)
|
||||||
.split(":");
|
.split(":");
|
||||||
hash = cryptography
|
hash = cryptography
|
||||||
@@ -60,6 +61,21 @@ function SharedData() {
|
|||||||
});
|
});
|
||||||
}, [encryptedData]);
|
}, [encryptedData]);
|
||||||
|
|
||||||
|
const validateAccountData = () => {
|
||||||
|
const builder = generateTransaction(BigInt(store.accountInfo?.sequence?.nonce || 0),
|
||||||
|
store.pubKey, store.nodeInfo.networkIdentifier, store.passPhrase)
|
||||||
|
|
||||||
|
const signedTx = builder.validate(decryptedData.map(e => ({
|
||||||
|
label: e.label,
|
||||||
|
value: Buffer.from(e.hash, 'hex')
|
||||||
|
})), address)
|
||||||
|
|
||||||
|
if (signedTx) {
|
||||||
|
fetchWrapper.post('transactions', {}, signedTx)
|
||||||
|
.catch((err) => console.log(err));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!passPhrase) return <Navigate to="/" replace={true} />;
|
if (!passPhrase) return <Navigate to="/" replace={true} />;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -87,6 +103,7 @@ function SharedData() {
|
|||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
|
{!hasError && <button className="mt-12 btn bg-indigo-500 hover:bg-indigo-600 text-white" onClick={validateAccountData}>Validate data</button>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -170,6 +170,7 @@ const Profile = observer (() => {
|
|||||||
const shareAccountData = () => {
|
const shareAccountData = () => {
|
||||||
const sharedData = store.decryptedAccountData.filter(item => selectedItems.includes(item.key))
|
const sharedData = store.decryptedAccountData.filter(item => selectedItems.includes(item.key))
|
||||||
store.pushSharedData(sharedData, publicKey)
|
store.pushSharedData(sharedData, publicKey)
|
||||||
|
cancelSharePanel();
|
||||||
}
|
}
|
||||||
|
|
||||||
const addDataParameters = () => {
|
const addDataParameters = () => {
|
||||||
|
|||||||
@@ -68,35 +68,35 @@ function request(method, url, headers = {}, token, body) {
|
|||||||
return fetch(prepareUrl(url), requestOptions);
|
return fetch(prepareUrl(url), requestOptions);
|
||||||
};
|
};
|
||||||
|
|
||||||
function get(url, headers, attempts = 1) {
|
function get(url, headers, attempts = 3) {
|
||||||
return handleRequest('GET', url, headers, attempts, null);
|
return handleRequest('GET', url, headers, attempts, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAuth(url, headers, attempts = 1) {
|
function getAuth(url, headers, attempts = 3) {
|
||||||
return handleRequest('GET', url, headers, attempts, store.tokenKey);
|
return handleRequest('GET', url, headers, attempts, store.tokenKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
function del(url, headers, attempts = 1) {
|
function del(url, headers, attempts = 3) {
|
||||||
return handleRequest('DELETE', url, headers, attempts, null);
|
return handleRequest('DELETE', url, headers, attempts, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
function delAuth(url, headers, attempts = 1) {
|
function delAuth(url, headers, attempts = 3) {
|
||||||
return handleRequest('DELETE', url, headers, attempts, store.tokenKey);
|
return handleRequest('DELETE', url, headers, attempts, store.tokenKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
function post(url, headers, body, attempts = 1) {
|
function post(url, headers, body, attempts = 3) {
|
||||||
return handleRequest('POST', url, headers, attempts, null, body);
|
return handleRequest('POST', url, headers, attempts, null, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
function postAuth(url, headers, body, attempts = 1) {
|
function postAuth(url, headers, body, attempts = 3) {
|
||||||
return handleRequest('POST', url, headers, attempts, store.tokenKey, body);
|
return handleRequest('POST', url, headers, attempts, store.tokenKey, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
function put(url, headers, body, attempts = 1) {
|
function put(url, headers, body, attempts = 3) {
|
||||||
return handleRequest('PUT', url, headers, attempts, null, body);
|
return handleRequest('PUT', url, headers, attempts, null, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
function putAuth(url, headers, body, attempts = 1) {
|
function putAuth(url, headers, body, attempts = 3) {
|
||||||
return handleRequest('PUT', url, headers, attempts, store.tokenKey, body);
|
return handleRequest('PUT', url, headers, attempts, store.tokenKey, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ class Store {
|
|||||||
networkIdentifier: this.nodeInfo.networkIdentifier,
|
networkIdentifier: this.nodeInfo.networkIdentifier,
|
||||||
lastBlockID: this.nodeInfo.lastBlockID,
|
lastBlockID: this.nodeInfo.lastBlockID,
|
||||||
},
|
},
|
||||||
{publickey: pubKey, shared: encryptSharedData(data, this.passPhrase, pubKey)}
|
{publickey: this.pubKey, shared: encryptSharedData(data, this.passPhrase, pubKey)}
|
||||||
)
|
)
|
||||||
.catch((err) => this.throwError(err));
|
.catch((err) => this.throwError(err));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
import resolveConfig from 'tailwindcss/resolveConfig';
|
import resolveConfig from 'tailwindcss/resolveConfig';
|
||||||
import {cryptography, transactions} from '@liskhq/lisk-client';
|
import {cryptography, transactions} from '@liskhq/lisk-client';
|
||||||
import {removeFeatureAssetSchema, setFeatureAssetSchema} from './Schemas';
|
import {
|
||||||
|
removeFeatureAssetSchema,
|
||||||
|
setFeatureAssetSchema,
|
||||||
|
validateFeatureAssetSchema,
|
||||||
|
} from './Schemas';
|
||||||
import {statusMap} from "../shared/statusMap";
|
import {statusMap} from "../shared/statusMap";
|
||||||
|
|
||||||
export const tailwindConfig = () => {
|
export const tailwindConfig = () => {
|
||||||
@@ -50,7 +54,7 @@ export const encryptAccountData = (data = [], passPhrase = '', pubKey = '') => {
|
|||||||
|
|
||||||
export const encryptSharedData = (data = [], passPhrase = '', pubKey = '') => {
|
export const encryptSharedData = (data = [], passPhrase = '', pubKey = '') => {
|
||||||
return data.map((item)=> {
|
return data.map((item)=> {
|
||||||
let value = cryptography.encryptMessageWithPassphrase(item.seed + ":" + item.value, passPhrase, pubKey);
|
let value = cryptography.encryptMessageWithPassphrase(item.seed + ":" + item.value, passPhrase, Buffer.from(pubKey, 'hex'));
|
||||||
return {
|
return {
|
||||||
label: item.key,
|
label: item.key,
|
||||||
value: value.encryptedMessage,
|
value: value.encryptedMessage,
|
||||||
@@ -109,6 +113,7 @@ export const generateTransaction = (nonce = BigInt(0), senderPublicKey = '', net
|
|||||||
return {
|
return {
|
||||||
update: (features) => generateSetTransaction(features, nonce, senderPublicKey, networkIdentifier, passPhrase, fee),
|
update: (features) => generateSetTransaction(features, nonce, senderPublicKey, networkIdentifier, passPhrase, fee),
|
||||||
remove: (features) => generateRemoveTransaction(features, nonce, senderPublicKey, networkIdentifier, passPhrase, fee),
|
remove: (features) => generateRemoveTransaction(features, nonce, senderPublicKey, networkIdentifier, passPhrase, fee),
|
||||||
|
validate: (features, recipientAddress) => generateValidateTransaction(features, nonce, senderPublicKey, networkIdentifier, passPhrase, fee, recipientAddress),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,3 +171,36 @@ export const generateRemoveTransaction = (features, nonce = BigInt(0), senderPub
|
|||||||
|
|
||||||
return signedTx;
|
return signedTx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const generateValidateTransaction = (features, nonce = BigInt(0), senderPublicKey = '', networkIdentifier = '', passPhrase = '', fee = BigInt(500000), recipientAddress='') => {
|
||||||
|
const tx = {
|
||||||
|
"moduleID": 1001,
|
||||||
|
"assetID": 11,
|
||||||
|
nonce,
|
||||||
|
senderPublicKey: Buffer.from(senderPublicKey, "hex"),
|
||||||
|
fee,
|
||||||
|
"asset": {
|
||||||
|
features,
|
||||||
|
recipientAddress: Buffer.from(recipientAddress, "hex")
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if(features.length === 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const signedTx = transactions.signTransaction(validateFeatureAssetSchema,
|
||||||
|
tx, Buffer.from(networkIdentifier, "hex"),
|
||||||
|
passPhrase)
|
||||||
|
|
||||||
|
signedTx.senderPublicKey = signedTx.senderPublicKey.toString("hex");
|
||||||
|
signedTx.asset.recipientAddress = signedTx.asset.recipientAddress.toString("hex");
|
||||||
|
signedTx.signatures[0] = signedTx.signatures[0].toString("hex");
|
||||||
|
signedTx.asset.features = signedTx.asset.features.map(feature => ({
|
||||||
|
...feature,
|
||||||
|
value: feature.value.toString("hex")
|
||||||
|
}))
|
||||||
|
|
||||||
|
delete signedTx.id;
|
||||||
|
|
||||||
|
return signedTx;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user