Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
22_23-J 16
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
22_23-J 16
22_23-J 16
Commits
53a2c0c0
Commit
53a2c0c0
authored
May 17, 2023
by
Ishini Kiridena
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
View NFT completed
parent
0d28b306
Changes
12
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
905 additions
and
5 deletions
+905
-5
ExpressBackend/route/patient-routes/nft-route.js
ExpressBackend/route/patient-routes/nft-route.js
+2
-2
ExpressBackend/route/practitioner-routes/get-asset-details-router.js
...end/route/practitioner-routes/get-asset-details-router.js
+29
-0
ExpressBackend/route/practitioner-routes/get-sent-nft-route.js
...ssBackend/route/practitioner-routes/get-sent-nft-route.js
+29
-0
ExpressBackend/server.js
ExpressBackend/server.js
+6
-0
emma-frontend/App.js
emma-frontend/App.js
+4
-0
emma-frontend/components/practitionerscreens/mainViewWithMenu.js
...ontend/components/practitionerscreens/mainViewWithMenu.js
+5
-1
emma-frontend/components/practitionerscreens/nft-view.js
emma-frontend/components/practitionerscreens/nft-view.js
+67
-0
emma-frontend/components/practitionerscreens/recievedNfts.js
emma-frontend/components/practitionerscreens/recievedNfts.js
+72
-0
emma-frontend/package-lock.json
emma-frontend/package-lock.json
+647
-1
emma-frontend/package.json
emma-frontend/package.json
+6
-1
emma-frontend/services/decryptByAssetKey.js
emma-frontend/services/decryptByAssetKey.js
+19
-0
emma-frontend/services/decryptByRsaKey.js
emma-frontend/services/decryptByRsaKey.js
+19
-0
No files found.
ExpressBackend/route/patient-routes/nft-route.js
View file @
53a2c0c0
...
...
@@ -312,7 +312,7 @@ router.post("/", async (req, res) => {
//add AES key and Asset code to DB
const
assetObj
=
new
AssetKey
({
assetcode
:
decryptedAssetCode
,
key
:
encodedA
esKey
,
key
:
a
esKey
,
});
try
{
...
...
@@ -426,7 +426,7 @@ router.post("/", async (req, res) => {
//add to the AssetKeyFullInfoDB
const
assetFullObj
=
new
AssetKeyFullInfo
({
assetcode
:
decryptedAssetCode
,
key
:
encodedA
esKey
,
key
:
a
esKey
,
cid
:
ipfsContentCID
,
to
:
decryptedPractitionerKey
,
});
...
...
ExpressBackend/route/practitioner-routes/get-asset-details-router.js
0 → 100644
View file @
53a2c0c0
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
;
ExpressBackend/route/practitioner-routes/get-sent-nft-route.js
0 → 100644
View file @
53a2c0c0
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
;
ExpressBackend/server.js
View file @
53a2c0c0
...
...
@@ -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
)
);
emma-frontend/App.js
View file @
53a2c0c0
...
...
@@ -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
/>
...
...
emma-frontend/components/practitionerscreens/mainViewWithMenu.js
View file @
53a2c0c0
...
...
@@ -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
>
);
...
...
emma-frontend/components/practitionerscreens/nft-view.js
0 → 100644
View file @
53a2c0c0
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
>
);
}
emma-frontend/components/practitionerscreens/recievedNfts.js
0 → 100644
View file @
53a2c0c0
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
"
,
},
});
emma-frontend/package-lock.json
View file @
53a2c0c0
This diff is collapsed.
Click to expand it.
emma-frontend/package.json
View file @
53a2c0c0
...
...
@@ -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"
...
...
emma-frontend/services/decryptByAssetKey.js
0 → 100644
View file @
53a2c0c0
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
;
emma-frontend/services/decryptByRsaKey.js
0 → 100644
View file @
53a2c0c0
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
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment