Commit 53a2c0c0 authored by Ishini Kiridena's avatar Ishini Kiridena

View NFT completed

parent 0d28b306
......@@ -312,7 +312,7 @@ router.post("/", async (req, res) => {
//add AES key and Asset code to DB
const assetObj = new AssetKey({
assetcode: decryptedAssetCode,
key: encodedAesKey,
key: aesKey,
});
try {
......@@ -426,7 +426,7 @@ router.post("/", async (req, res) => {
//add to the AssetKeyFullInfoDB
const assetFullObj = new AssetKeyFullInfo({
assetcode: decryptedAssetCode,
key: encodedAesKey,
key: aesKey,
cid: ipfsContentCID,
to: decryptedPractitionerKey,
});
......
const express = require("express");
const router = express.Router();
const AssetKeyFullInfo = require("../../model/stellar/assetKeyFull");
router.get("/:assetcode", async (req, res) => {
const assetCode = req.params.assetcode;
try {
const assetData = await AssetKeyFullInfo.findOne({
assetcode: assetCode,
});
res.status(200).json({
data: assetData,
});
console.log("/getassetdata - Getting asset data successful");
} catch (errorWhenGettingThePatients) {
console.log(
"Getting asset data failed: ERROR : ",
errorWhenGettingThePatients
);
console.log("/getassetdata - Getting asset data failed");
res.status(500).json({
error: "Getting asset data failed: ERROR :",
errorWhenGettingThePatients,
});
}
});
module.exports = router;
const express = require("express");
const router = express.Router();
const NFTRequest = require("./../../model/stellar/nftRequests");
router.get("/:practitionerKey", async (req, res) => {
const practitionerKey = req.params.practitionerKey;
try {
const nftData = await NFTRequest.find({
requesterpk: practitionerKey,
});
res.status(200).json({
data: nftData,
});
console.log("/sentnft - Getting sent NFTs completed");
} catch (errorWhenGettingThePatients) {
console.log(
"Getting sent NFTs failed: ERROR : ",
errorWhenGettingThePatients
);
console.log("/sentnft - Getting sent NFTs failed");
res.status(500).json({
error: "Getting sent NFTs failed: ERROR : ",
errorWhenGettingThePatients,
});
}
});
module.exports = router;
......@@ -66,6 +66,12 @@ app.use("/practitioner/treatingPatients", treatingPatients);
const assetCodes = require("./route/practitioner-routes/get-assetcode-practitioner-route");
app.use("/practitioner/getassetcode", assetCodes);
const sentNfts = require("./route/practitioner-routes/get-sent-nft-route");
app.use("/practitioner/sentnft", sentNfts);
const assetData = require("./route/practitioner-routes/get-asset-details-router");
app.use("/practitioner/getassetdata", assetData);
app.listen(process.env.SERVER_PORT, () =>
console.log("Server started on port " + process.env.SERVER_PORT)
);
......@@ -24,6 +24,8 @@ import PatientRequests from "./components/practitionerscreens/patientRequestsVie
import PatientLogin from "./components/patientscreens/registration/login";
import PractitionerLogin from "./components/practitionerscreens/login";
import TreatingPatients from "./components/practitionerscreens/treatingPatients";
import ReceivedNFT from "./components/practitionerscreens/recievedNfts";
import NftView from "./components/practitionerscreens/nft-view";
const Stack = createStackNavigator();
......@@ -132,6 +134,8 @@ export default function App() {
component={PractitionerLogin}
/>
<Stack.Screen name="TreatingPatients" component={TreatingPatients} />
<Stack.Screen name="ReceivedNFT" component={ReceivedNFT} />
<Stack.Screen name="NftView" component={NftView} />
</Stack.Navigator>
) : (
<SplashScreenComponent />
......
......@@ -10,6 +10,10 @@ export default function PractitionerMainView({ navigation }) {
navigation.navigate("TreatingPatients");
};
const handleView = () => {
navigation.navigate("ReceivedNFT");
};
return (
<View style={styles.container}>
<View style={styles.buttonContainer}>
......@@ -19,7 +23,7 @@ export default function PractitionerMainView({ navigation }) {
<Button title="Request EHRs" onPress={() => handleRequesting()} />
</View>
<View style={styles.buttonContainer}>
<Button title="Others" onPress={() => handleButtonPress("Others")} />
<Button title="View NFTs" onPress={() => handleView()} />
</View>
</View>
);
......
import { useEffect, useState } from "react";
import { LOCALBACKEND } from "../../env";
import AsyncStorage from "@react-native-async-storage/async-storage";
import RSADecrypt from "../../services/decryptByRsaKey";
import DecryptWithAssetKey from "../../services/decryptByAssetKey";
import { WebView } from "react-native-webview";
import { View, Text, useWindowDimensions, ScrollView } from "react-native";
import RenderHTML from "react-native-render-html";
export default function NftView({ navigation, route }) {
const [data, setData] = useState({});
const [aesKey, setAesKey] = useState("");
const [cid, setCid] = useState("");
const [ipfsContent, setIpfsContent] = useState("");
const [decryptedContent, setDecrypted] = useState("");
const { width } = useWindowDimensions();
useEffect(() => {
fetchRequests();
}, []);
const fetchRequests = async () => {
console.log("Asset code ", assetCode);
const assetCode = route.params.assetcode;
try {
const assetUrl = LOCALBACKEND + `/practitioner/getassetdata/${assetCode}`;
console.log(assetUrl);
const response = await fetch(assetUrl);
const json = await response.json();
setData(json.data);
setAesKey(data.key);
setCid(data.cid);
console.log(json.data);
//get the content from the IPFS
const ipfsContentCID = json.data.cid;
const ipfsUrl = "https://ipfs.io/ipfs/" + ipfsContentCID;
console.log(ipfsUrl);
try {
const ipfsResponse = await fetch(ipfsUrl);
const ipfsText = await ipfsResponse.text();
setIpfsContent(ipfsText);
console.log(ipfsText);
const decryptedIpfsContent = DecryptWithAssetKey(
json.data.key,
ipfsText
);
setDecrypted(decryptedIpfsContent);
console.log(decryptedIpfsContent);
} catch (errorWhenGGettingIPFSContent) {
console.error(
"Error when getting IPFS content :",
errorWhenGGettingIPFSContent
);
}
} catch (errorWhenGettingNftDetails) {
console.log("Error when getting NFT details");
}
};
return (
<ScrollView>
<RenderHTML contentWidth={width} source={{ html: decryptedContent }} />
</ScrollView>
);
}
import { useEffect, useState } from "react";
import { LOCALBACKEND } from "../../env";
import { Button, StyleSheet, View, Text } from "react-native";
import AsyncStorage from "@react-native-async-storage/async-storage";
import EncryptWithServerKey from "../../services/encryptByServerKey";
export default function ReceivedNFT({ navigation }) {
const [data, setData] = useState([]);
useEffect(() => {
fetchRequests();
}, []);
const fetchRequests = async () => {
//get key from async storage
try {
const practitionerKey = await AsyncStorage.getItem(
"practitionerStellarPublicKey"
);
try {
const requestUrl =
LOCALBACKEND + `/practitioner/sentnft/${practitionerKey}`;
console.log(requestUrl);
const response = await fetch(requestUrl);
const json = await response.json();
setData(json.data);
} catch (errorFetchingRequests) {
console.log(
"Error when fetching request data : ",
errorFetchingRequests
);
}
} catch (errorWhenGettingKey) {
console.log(
"Error when getting the public key from the async storage : ",
errorWhenGettingKey
);
}
};
const renderItem = (item) => {
return (
<View key={item._id}>
<Text>Key: {item.assetcode}</Text>
<Button title="View NFT" onPress={() => handleViewNFT(item)}></Button>
</View>
);
};
const handleViewNFT = async (item) => {
//route the NFT view ui with the item object
navigation.navigate("NftView", item);
};
return (
<View style={styles.container}>{data.map((item) => renderItem(item))}</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
},
text: {
fontSize: 24,
fontWeight: "bold",
},
});
This diff is collapsed.
......@@ -16,13 +16,18 @@
"@react-navigation/native": "^6.1.6",
"@react-navigation/stack": "^6.3.16",
"expo": "~48.0.15",
"expo-crypto": "~12.2.1",
"expo-status-bar": "~1.4.4",
"react": "18.2.0",
"react-native": "0.71.8",
"react-native-base64": "^0.2.1",
"react-native-crypto-js": "^1.0.0",
"react-native-datepicker": "^1.7.2",
"react-native-render-html": "^6.3.4",
"react-native-rsa-native": "^2.0.5",
"react-native-simple-radio-button": "^2.7.4",
"react-native-toast-message": "^2.1.6"
"react-native-toast-message": "^2.1.6",
"react-native-webview": "11.26.0"
},
"devDependencies": {
"@babel/core": "^7.20.0"
......
import CryptoJS from "react-native-crypto-js";
function DecryptWithAssetKey(aesKey, encryptedTxt) {
console.log(aesKey, encryptedTxt);
const key = CryptoJS.enc.Utf8.parse(aesKey);
const options = {
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7,
iv: CryptoJS.enc.Utf8.parse(aesKey),
};
const decryptedBytes = CryptoJS.AES.decrypt(encryptedTxt, key, options);
const decryptedTxt = decryptedBytes.toString(CryptoJS.enc.Utf8);
console.log(decryptedTxt);
return decryptedTxt;
}
export default DecryptWithAssetKey;
import { RSA } from "react-native-rsa-native";
import { decode as base64Decode } from "react-native-base64";
async function RSADecrypt(privateKey, encryptedString) {
const encryptedBytes = base64Decode(encryptedString);
const ecnryptedRsaKey = base64Decode(privateKey);
console.log("=====================", ecnryptedRsaKey);
try {
const decryptedData = await RSA.decrypt(encryptedBytes, {
ecnryptedRsaKey,
});
return decryptedData;
} catch (error) {
console.error("RSA decryption failed:", error);
return null;
}
}
export default RSADecrypt;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment