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
b39f5116
Commit
b39f5116
authored
Apr 15, 2023
by
Ishini Kiridena
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
asset code generation moved to request done
parent
47e650dd
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
115 additions
and
132 deletions
+115
-132
ExpressBackend/model/patient/patient.js
ExpressBackend/model/patient/patient.js
+0
-1
ExpressBackend/route/patient-routes/register-route.js
ExpressBackend/route/patient-routes/register-route.js
+58
-87
ExpressBackend/route/practitioner-routes/requestnft-route.js
ExpressBackend/route/practitioner-routes/requestnft-route.js
+55
-41
ExpressBackend/services/assetCodeGetterFromDB.js
ExpressBackend/services/assetCodeGetterFromDB.js
+2
-3
No files found.
ExpressBackend/model/patient/patient.js
View file @
b39f5116
...
...
@@ -8,7 +8,6 @@ const Patient = new mongoose.Schema({
rsa
:
String
,
genesishash
:
String
,
currenthash
:
String
,
keysequence
:
String
,
issuerpk
:
String
,
issuersk
:
String
,
timestamp
:
String
,
...
...
ExpressBackend/route/patient-routes/register-route.js
View file @
b39f5116
...
...
@@ -289,104 +289,75 @@ router.post("/", async (req, res) => {
const
b64RSApk
=
btoa
(
RSAPK
);
const
b64RSAsk
=
btoa
(
RSASK
);
var
newAssetCode
=
""
;
//generate new account
try
{
const
result
=
await
GenerateKeyPairAndCreateAccount
();
console
.
log
(
"
Issuer Public Key:
"
,
result
.
publicKey
);
console
.
log
(
"
Issuer Private Key:
"
,
result
.
privateKey
);
//generate NFT sequence NO as asset ID
GenerateRandomAssetCode
()
.
then
(
async
(
assetCode
)
=>
{
newAssetCode
=
assetCode
;
console
.
log
(
"
New asset code generated :
"
,
newAssetCode
);
//generate new account
try
{
const
result
=
await
GenerateKeyPairAndCreateAccount
();
console
.
log
(
"
Issuer Public Key:
"
,
result
.
publicKey
);
console
.
log
(
"
Issuer Private Key:
"
,
result
.
privateKey
);
//create the user collection object to be added to the DB
const
userCollectionObject
=
new
UserSchema
({
username
:
decryptedUserName
,
password
:
req
.
body
.
password
,
email
:
decryptedEmail
,
publickey
:
userKeyPair
.
publicKey
(),
rsa
:
b64RSApk
,
genesishash
:
genesisTxnResult
.
hash
,
currenthash
:
genesisTxnResult
.
hash
,
timestamp
:
timestamp
,
keysequence
:
newAssetCode
,
issuerpk
:
EncryptionService
.
EncryptWithServerKey
(
result
.
publicKey
),
issuersk
:
EncryptionService
.
EncryptWithServerKey
(
result
.
privateKey
),
});
//create the user collection object to be added to the DB
const
userCollectionObject
=
new
UserSchema
({
username
:
decryptedUserName
,
password
:
req
.
body
.
password
,
email
:
decryptedEmail
,
publickey
:
userKeyPair
.
publicKey
(),
rsa
:
b64RSApk
,
genesishash
:
genesisTxnResult
.
hash
,
currenthash
:
genesisTxnResult
.
hash
,
timestamp
:
timestamp
,
issuerpk
:
EncryptionService
.
EncryptWithServerKey
(
result
.
publicKey
),
issuersk
:
EncryptionService
.
EncryptWithServerKey
(
result
.
privateKey
),
});
//save the user collection object to the database
try
{
const
saveUserInCollection
=
await
userCollectionObject
.
save
();
console
.
log
(
"
User details added to the DB
"
+
saveUserInCollection
);
console
.
log
(
"
Public key:
"
+
userKeyPair
.
publicKey
());
console
.
log
(
"
Secret:
"
+
userKeyPair
.
secret
());
res
.
status
(
200
).
json
({
message
:
"
User details added to the blockchain
"
,
hash
:
genesisTxnResult
.
hash
,
pubkey
:
EncryptionService
.
EncryptWithServerKey
(
userKeyPair
.
publicKey
()
),
seed
:
EncryptionService
.
EncryptWithServerKey
(
userKeyPair
.
secret
()
),
rsapk
:
EncryptionService
.
EncryptWithServerKey
(
b64RSApk
),
rsask
:
EncryptionService
.
EncryptWithServerKey
(
b64RSAsk
),
});
console
.
log
(
"
/patient/register - register patient details successful
"
);
}
catch
(
errorWhenAddingUserToDB
)
{
console
.
log
(
"
Error when adding user details to the database :
"
+
errorWhenAddingUserToDB
);
res
.
status
(
500
).
json
({
message
:
"
Error when adding user details to the database :
"
+
errorWhenAddingUserToDB
,
});
console
.
log
(
"
/patient/register - register patient details unsuccessful
"
);
}
}
catch
(
errWhenGeneratingIssuerAccount
)
{
console
.
log
(
"
Error when generating issuer account :
"
+
errWhenGeneratingIssuerAccount
);
res
.
status
(
500
).
json
({
message
:
"
Error when generating issuer account :
"
+
errWhenGeneratingIssuerAccount
,
});
console
.
log
(
"
/patient/register - register patient details unsuccessful
"
);
}
})
.
catch
((
errWhenGeneratingAssetCode
)
=>
{
//save the user collection object to the database
try
{
const
saveUserInCollection
=
await
userCollectionObject
.
save
();
console
.
log
(
"
User details added to the DB
"
+
saveUserInCollection
);
console
.
log
(
"
Public key:
"
+
userKeyPair
.
publicKey
());
console
.
log
(
"
Secret:
"
+
userKeyPair
.
secret
());
res
.
status
(
200
).
json
({
message
:
"
User details added to the blockchain
"
,
hash
:
genesisTxnResult
.
hash
,
pubkey
:
EncryptionService
.
EncryptWithServerKey
(
userKeyPair
.
publicKey
()
),
seed
:
EncryptionService
.
EncryptWithServerKey
(
userKeyPair
.
secret
()
),
rsapk
:
EncryptionService
.
EncryptWithServerKey
(
b64RSApk
),
rsask
:
EncryptionService
.
EncryptWithServerKey
(
b64RSAsk
),
});
console
.
log
(
"
/patient/register - register patient details successful
"
);
}
catch
(
errorWhenAddingUserToDB
)
{
console
.
log
(
"
Error when generating asset code :
"
+
errWhenGeneratingAssetCode
"
Error when adding user details to the database :
"
+
errorWhenAddingUserToDB
);
res
.
status
(
500
).
json
({
message
:
"
Error when
generating asset cod
e :
"
+
err
WhenGeneratingAssetCode
,
"
Error when
adding user details to the databas
e :
"
+
err
orWhenAddingUserToDB
,
});
console
.
log
(
"
/patient/register - register patient details unsuccessful
"
);
}
}
catch
(
errWhenGeneratingIssuerAccount
)
{
console
.
log
(
"
Error when generating issuer account :
"
+
errWhenGeneratingIssuerAccount
);
res
.
status
(
500
).
json
({
message
:
"
Error when generating issuer account :
"
+
errWhenGeneratingIssuerAccount
,
});
console
.
log
(
"
/patient/register - register patient details unsuccessful
"
);
}
}
catch
(
error
)
{
console
.
log
(
"
Error when sending genesis transaction to blockchain:
"
+
error
...
...
ExpressBackend/route/practitioner-routes/requestnft-route.js
View file @
b39f5116
const
express
=
require
(
"
express
"
);
const
router
=
express
.
Router
();
const
GetIssuer
AndAssetCode
=
require
(
"
./../../services/assetCodeGetterFromDB
"
);
const
GetIssuer
=
require
(
"
./../../services/assetCodeGetterFromDB
"
);
const
DecryptWithServerKey
=
require
(
"
./../../services/decryptionservice
"
);
const
StellarSdk
=
require
(
"
stellar-sdk
"
);
const
CreateTrustline
=
require
(
"
./../../services/trustlineCreator
"
);
const
NFTRequest
=
require
(
"
./../../model/stellar/nftRequests
"
);
const
GenerateRandomAssetCode
=
require
(
"
./../../services/assetCodeGenerator
"
);
require
(
"
dotenv
"
).
config
();
router
.
post
(
"
/
"
,
async
(
req
,
res
)
=>
{
...
...
@@ -13,52 +14,65 @@ router.post("/", async (req, res) => {
const
patientKey
=
req
.
body
.
patient
;
const
practitionerRSA
=
req
.
body
.
practitionerrsa
;
//take the
current asset code and the
issuer key for the patient from the data base
const
assetAndIssuer
=
await
GetIssuerAndAssetCode
(
"
patients
"
,
patientKey
);
//take the issuer key for the patient from the data base
const
issuerRes
=
await
GetIssuer
(
"
patients
"
,
patientKey
);
console
.
log
(
"
AC
"
,
assetAndIssuer
.
assetCode
);
console
.
log
(
"
IP
"
,
DecryptWithServerKey
(
assetAndIssuer
.
issuerKey
));
//Generate the asset code
GenerateRandomAssetCode
()
.
then
((
assetCode
)
=>
{
console
.
log
(
"
AC
"
,
assetCode
);
console
.
log
(
"
IP
"
,
DecryptWithServerKey
(
issuerRes
.
issuerKey
));
const
issuerPK
=
DecryptWithServerKey
(
issuerRes
.
issuerKey
);
const
assetCode
=
assetAndIssuer
.
assetCode
;
const
issuerPK
=
DecryptWithServerKey
(
assetAndIssuer
.
issuerKey
);
CreateTrustline
(
assetCode
,
issuerPK
,
practitionerSK
)
.
then
(
async
(
result
)
=>
{
console
.
log
(
"
Trust line created successfully!
"
);
//add request to DB
const
nftRequestObj
=
new
NFTRequest
({
assetcode
:
assetCode
,
issuerpk
:
issuerPK
,
requesterpk
:
practitionerPK
,
requesterrsa
:
practitionerRSA
,
distributorpk
:
patientKey
,
status
:
"
Pending
"
,
});
try
{
const
saveRequest
=
await
nftRequestObj
.
save
();
console
.
log
(
"
NFT request saved to database :
"
+
saveRequest
);
res
.
status
(
200
).
json
({
message
:
"
NFT request saved to database
"
,
});
console
.
log
(
"
/practitioner/requestnft - requesting NFT success
"
);
}
catch
(
errorWhenAddingRequestToDB
)
{
console
.
log
(
"
Error when adding NFT request to DB :
"
,
errorWhenAddingRequestToDB
);
console
.
log
(
"
/practitioner/requestnft - requesting NFT failed
"
);
return
res
.
status
(
500
).
json
({
message
:
"
Error when adding NFT request to DB :
"
,
errorWhenAddingRequestToDB
,
CreateTrustline
(
assetCode
,
issuerPK
,
practitionerSK
)
.
then
(
async
(
result
)
=>
{
console
.
log
(
"
Trust line created successfully!
"
);
//add request to DB
const
nftRequestObj
=
new
NFTRequest
({
assetcode
:
assetCode
,
issuerpk
:
issuerPK
,
requesterpk
:
practitionerPK
,
requesterrsa
:
practitionerRSA
,
distributorpk
:
patientKey
,
status
:
"
Pending
"
,
});
try
{
const
saveRequest
=
await
nftRequestObj
.
save
();
console
.
log
(
"
NFT request saved to database :
"
+
saveRequest
);
res
.
status
(
200
).
json
({
message
:
"
NFT request saved to database
"
,
});
console
.
log
(
"
/practitioner/requestnft - requesting NFT success
"
);
}
catch
(
errorWhenAddingRequestToDB
)
{
console
.
log
(
"
Error when adding NFT request to DB :
"
,
errorWhenAddingRequestToDB
);
console
.
log
(
"
/practitioner/requestnft - requesting NFT failed
"
);
return
res
.
status
(
500
).
json
({
message
:
"
Error when adding NFT request to DB :
"
,
errorWhenAddingRequestToDB
,
});
}
})
.
catch
((
error
)
=>
{
console
.
log
(
"
Failed to create the trust line :
"
,
error
);
console
.
log
(
"
/practitioner/requestnft - requesting NFT failed
"
);
return
res
.
status
(
500
).
json
({
message
:
"
Failed to create the trust line :
"
,
error
,
});
});
}
})
.
catch
((
error
)
=>
{
console
.
log
(
"
Failed to create the trust line :
"
,
error
);
.
catch
((
errWhenGeneratingAssetCode
)
=>
{
console
.
log
(
"
Failed to generate asset code :
"
,
errWhenGeneratingAssetCode
);
console
.
log
(
"
/practitioner/requestnft - requesting NFT failed
"
);
return
res
.
status
(
500
).
json
({
message
:
"
Failed to
create the trust lin
e :
"
,
err
or
,
message
:
"
Failed to
generate asset cod
e :
"
,
err
WhenGeneratingAssetCode
,
});
});
});
...
...
ExpressBackend/services/assetCodeGetterFromDB.js
View file @
b39f5116
const
MongoClient
=
require
(
"
mongodb
"
).
MongoClient
;
async
function
GetIssuer
AndAssetCode
(
collectionName
,
publicKey
)
{
async
function
GetIssuer
(
collectionName
,
publicKey
)
{
const
uri
=
process
.
env
.
DATABASE_URL
;
const
client
=
new
MongoClient
(
uri
,
{
useNewUrlParser
:
true
,
...
...
@@ -19,10 +19,9 @@ async function GetIssuerAndAssetCode(collectionName, publicKey) {
return
{
issuerKey
:
result
.
issuerpk
,
assetCode
:
result
.
keysequence
,
};
}
finally
{
await
client
.
close
();
}
}
module
.
exports
=
GetIssuer
AndAssetCode
;
module
.
exports
=
GetIssuer
;
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