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
3b425031
Commit
3b425031
authored
Dec 30, 2022
by
Ishini Kiridena
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Patient registration completed
parent
02330adc
Changes
13
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
751 additions
and
4 deletions
+751
-4
ExpressBackend/.env
ExpressBackend/.env
+4
-1
ExpressBackend/model/patient/patient.js
ExpressBackend/model/patient/patient.js
+13
-0
ExpressBackend/model/patient/registration.js
ExpressBackend/model/patient/registration.js
+10
-0
ExpressBackend/model/patientOld.js
ExpressBackend/model/patientOld.js
+0
-0
ExpressBackend/model/stellar/accountCreate.js
ExpressBackend/model/stellar/accountCreate.js
+10
-0
ExpressBackend/package-lock.json
ExpressBackend/package-lock.json
+424
-1
ExpressBackend/package.json
ExpressBackend/package.json
+4
-1
ExpressBackend/route/patient-routes/emotion-route.js
ExpressBackend/route/patient-routes/emotion-route.js
+0
-0
ExpressBackend/route/patient-routes/register-route.js
ExpressBackend/route/patient-routes/register-route.js
+231
-0
ExpressBackend/server.js
ExpressBackend/server.js
+5
-1
ExpressBackend/services/decryptionservice.js
ExpressBackend/services/decryptionservice.js
+18
-0
ExpressBackend/services/encryptionservice.js
ExpressBackend/services/encryptionservice.js
+32
-0
ExpressBackend/services/stellarservice.js
ExpressBackend/services/stellarservice.js
+0
-0
No files found.
ExpressBackend/.env
View file @
3b425031
STELLARTESTNET="https://horizon-testnet.stellar.org"
STELLARPUBNET="https://horizon.stellar.org"
DATABASE_URL="mongodb+srv://dbUser:1997Ishini%21@cluster0.lmazo.mongodb.net/research?retryWrites=true&w=majority"
SERVER_PORT=4000
\ No newline at end of file
SERVER_PORT=4000
STELLARPUBLICKEY="GB3U2F6MWAQ43O6J4AIUQXEMTK5XQZWURC3SF4D37DPBFRY4HCZGRBLG"
STELLARSEED="SBUXCZ7F7G5Z3QK3NKM52UWVJWFSLEVVGQOCIEWEJY4DOYMYVOMUTS4B"
AESKEY="QfTjWnZr4u7x!A%D"
\ No newline at end of file
ExpressBackend/model/patient/patient.js
0 → 100644
View file @
3b425031
const
mongoose
=
require
(
"
mongoose
"
);
const
Patient
=
new
mongoose
.
Schema
({
username
:
String
,
password
:
String
,
email
:
String
,
publickey
:
String
,
genesishash
:
String
,
currenthash
:
String
,
timestamp
:
Number
,
});
module
.
exports
=
mongoose
.
model
(
"
Patient
"
,
Patient
);
ExpressBackend/model/patient/registration.js
0 → 100644
View file @
3b425031
const
mongoose
=
require
(
"
mongoose
"
);
//TODO: add the needed other details to the object
const
regRequest
=
new
mongoose
.
Schema
({
email
:
String
,
username
:
String
,
password
:
String
,
});
module
.
exports
=
mongoose
.
model
(
"
PatientRegistrationSchema
"
,
regRequest
);
ExpressBackend/model/patient.js
→
ExpressBackend/model/patient
Old
.js
View file @
3b425031
File moved
ExpressBackend/model/stellar/accountCreate.js
0 → 100644
View file @
3b425031
const
mongoose
=
require
(
"
mongoose
"
);
const
accountCreate
=
new
mongoose
.
Schema
({
publickey
:
String
,
amount
:
String
,
timestamp
:
Number
,
transactionhash
:
String
,
});
module
.
exports
=
mongoose
.
model
(
"
AccountCreated
"
,
accountCreate
);
ExpressBackend/package-lock.json
View file @
3b425031
This diff is collapsed.
Click to expand it.
ExpressBackend/package.json
View file @
3b425031
...
...
@@ -15,11 +15,14 @@
"license"
:
"ISC"
,
"dependencies"
:
{
"cors"
:
"^2.8.5"
,
"crypto-js"
:
"^4.1.1"
,
"express"
:
"^4.18.2"
,
"mongoose"
:
"^6.8.0"
"mongoose"
:
"^6.8.0"
,
"stellar-sdk"
:
"^10.4.1"
},
"devDependencies"
:
{
"@types/cors"
:
"^2.8.13"
,
"@types/crypto-js"
:
"^4.1.1"
,
"@types/express"
:
"^4.17.15"
,
"@types/nodemon"
:
"^1.19.2"
,
"dotenv"
:
"^16.0.3"
,
...
...
ExpressBackend/route/patient
R
oute.js
→
ExpressBackend/route/patient
-routes/emotion-r
oute.js
View file @
3b425031
File moved
ExpressBackend/route/patient-routes/register-route.js
0 → 100644
View file @
3b425031
const
express
=
require
(
"
express
"
);
const
router
=
express
.
Router
();
const
RegisterRequestSchema
=
require
(
"
./../../model/patient/registration
"
);
require
(
"
dotenv
"
).
config
();
const
StellarSDK
=
require
(
"
stellar-sdk
"
);
const
DecryptWithServerKey
=
require
(
"
./../../services/decryptionservice
"
);
const
EncryptionService
=
require
(
"
./../../services/encryptionservice
"
);
const
AccountCreateCollection
=
require
(
"
../../model/stellar/accountCreate
"
);
const
UserSchema
=
require
(
"
../../model/patient/patient
"
);
router
.
post
(
"
/
"
,
async
(
req
,
res
)
=>
{
//decrypt user request details
const
decryptedEmail
=
DecryptWithServerKey
(
req
.
body
.
email
);
const
decryptedPassword
=
DecryptWithServerKey
(
req
.
body
.
password
);
const
decryptedUserName
=
DecryptWithServerKey
(
req
.
body
.
email
);
//catching the request
const
request
=
new
RegisterRequestSchema
({
email
:
req
.
body
.
email
,
username
:
req
.
body
.
username
,
password
:
req
.
body
.
password
,
});
console
.
log
(
request
);
//get the server key pair
const
serverSourceKeyPair
=
StellarSDK
.
Keypair
.
fromSecret
(
process
.
env
.
STELLARSEED
);
const
serverPubKey
=
serverSourceKeyPair
.
publicKey
();
const
server
=
new
StellarSDK
.
Server
(
process
.
env
.
STELLARTESTNET
);
//load server account
const
account
=
await
server
.
loadAccount
(
serverPubKey
);
const
fee
=
await
server
.
fetchBaseFee
();
//generate random keypair
const
userKeyPair
=
StellarSDK
.
Keypair
.
random
();
//build the account funding transaction
const
accCreateTransaction
=
new
StellarSDK
.
TransactionBuilder
(
account
,
{
fee
,
networkPassphrase
:
StellarSDK
.
Networks
.
TESTNET
,
})
.
addMemo
(
StellarSDK
.
Memo
.
text
(
"
Create account
"
))
.
addOperation
(
StellarSDK
.
Operation
.
createAccount
({
destination
:
userKeyPair
.
publicKey
(),
startingBalance
:
"
10
"
,
})
)
.
setTimeout
(
30
)
.
build
();
//sign the transaction
accCreateTransaction
.
sign
(
serverSourceKeyPair
);
//send account creation transaction to BC
try
{
const
accCreateTxnResult
=
await
server
.
submitTransaction
(
accCreateTransaction
);
console
.
log
(
"
New user account created: HASH :
"
,
accCreateTxnResult
.
hash
);
console
.
log
(
"
View account creation transaction at : https://horizon-testnet.stellar.org/transactions/
"
+
accCreateTxnResult
.
hash
);
//create the account creation details collection object
const
createAccountObj
=
new
AccountCreateCollection
({
publickey
:
userKeyPair
.
publicKey
(),
amount
:
"
10XLM
"
,
timestamp
:
Date
.
now
(),
transactionhash
:
accCreateTxnResult
.
hash
,
});
//save the account creation details to the database
try
{
const
saveInCollection
=
await
createAccountObj
.
save
();
console
.
log
(
"
Account creation details saved in the database
"
+
saveInCollection
);
//encrypt user entered details with stellar seed
const
encEmail
=
EncryptionService
.
EncryptWithStellarSeed
(
request
.
email
,
userKeyPair
.
secret
()
);
const
encUsername
=
EncryptionService
.
EncryptWithStellarSeed
(
request
.
username
,
userKeyPair
.
secret
()
);
const
encPassword
=
EncryptionService
.
EncryptWithStellarSeed
(
request
.
password
,
userKeyPair
.
secret
()
);
//get the user keypair
const
userSourceKeyPair
=
StellarSDK
.
Keypair
.
fromSecret
(
userKeyPair
.
secret
()
);
const
userSourcePublicKey
=
userSourceKeyPair
.
publicKey
();
//load user account
const
userAccount
=
await
server
.
loadAccount
(
userSourcePublicKey
);
//build genesis transaction
const
genesisTransaction
=
new
StellarSDK
.
TransactionBuilder
(
userAccount
,
{
fee
,
networkPassphrase
:
StellarSDK
.
Networks
.
TESTNET
,
}
)
.
addMemo
(
StellarSDK
.
Memo
.
text
(
"
Genesis
"
))
.
addOperation
(
StellarSDK
.
Operation
.
manageData
({
name
:
"
Email Address
"
,
value
:
encEmail
,
})
)
.
addOperation
(
StellarSDK
.
Operation
.
manageData
({
name
:
"
Username
"
,
value
:
encUsername
,
})
)
.
addOperation
(
StellarSDK
.
Operation
.
manageData
({
name
:
"
Previous
"
,
value
:
""
,
})
)
.
setTimeout
(
30
)
.
build
();
//sign the genesis transaction
genesisTransaction
.
sign
(
userSourceKeyPair
);
//send the genesis transaction
try
{
const
genesisTxnResult
=
await
server
.
submitTransaction
(
genesisTransaction
);
console
.
log
(
"
Genesis transaction submitted: HASH :
"
,
genesisTxnResult
.
hash
);
console
.
log
(
"
View genesis transaction at : https://horizon-testnet.stellar.org/transactions/
"
+
genesisTxnResult
.
hash
);
//create the user collection object to be added to the DB
const
userCollectionObject
=
new
UserSchema
({
username
:
req
.
body
.
username
,
password
:
req
.
body
.
password
,
email
:
req
.
body
.
email
,
publickey
:
userKeyPair
.
publicKey
(),
genesishash
:
genesisTxnResult
.
hash
,
currenthash
:
genesisTxnResult
.
hash
,
timestamp
:
Date
.
now
(),
});
//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
()),
});
console
.
log
(
"
/patient/register - register patient details successful
"
);
}
catch
(
error
)
{
console
.
log
(
"
Error when adding user details to the blockchain :
"
+
error
);
res
.
status
(
500
).
json
({
message
:
"
Error when adding user details to the blockchain :
"
+
error
,
});
console
.
log
(
"
/patient/register - register patient details unsuccessful
"
);
}
}
catch
(
error
)
{
console
.
log
(
"
Error when sending genesis transaction to blockchain:
"
+
error
);
res
.
status
(
500
).
json
({
message
:
"
Error when sending genesis transaction to blockchain:
"
+
error
,
});
console
.
log
(
"
/patient/register - register patient details unsuccessful
"
);
}
}
catch
(
error
)
{
console
.
log
(
"
Error when sending account creation transaction details to DB :
"
+
error
);
res
.
status
(
500
).
json
({
message
:
"
Error when sending account creation transaction details to DB :
"
+
error
,
});
console
.
log
(
"
/patient/register - register patient details unsuccessful
"
);
}
}
catch
(
error
)
{
console
.
log
(
"
Error when sending account creation transaction to blockchain:
"
+
error
);
res
.
status
(
500
).
json
({
message
:
"
Error when sending account creation transaction to blockchain:
"
+
error
,
});
console
.
log
(
"
/patient/register - register patient details unsuccessful
"
);
}
});
module
.
exports
=
router
;
ExpressBackend/server.js
View file @
3b425031
...
...
@@ -4,7 +4,7 @@ const app = express();
const
mongoose
=
require
(
"
mongoose
"
);
var
cors
=
require
(
"
cors
"
);
mongoose
.
connect
(
process
.
env
.
DATABASE_URL
,
{
useNewUrlParser
:
true
}
);
mongoose
.
connect
(
process
.
env
.
DATABASE_URL
);
const
db
=
mongoose
.
connection
;
db
.
on
(
"
error
"
,
(
error
)
=>
console
.
error
(
error
));
db
.
once
(
"
open
"
,
(
error
)
=>
console
.
log
(
"
Connected to DB..
"
));
...
...
@@ -16,6 +16,10 @@ app.use(express.json());
const
healthRoute
=
require
(
"
./route/serverHealth
"
);
app
.
use
(
"
/health
"
,
healthRoute
);
//patient routes
const
patientRegister
=
require
(
"
./route/patient-routes/register-route
"
);
app
.
use
(
"
/patient/register
"
,
patientRegister
);
app
.
listen
(
process
.
env
.
SERVER_PORT
,
()
=>
console
.
log
(
"
Server started on port
"
+
process
.
env
.
SERVER_PORT
)
);
ExpressBackend/services/decryptionservice.js
View file @
3b425031
const
cryptojs
=
require
(
"
crypto-js
"
);
require
(
"
dotenv
"
).
config
();
function
DecryptWithServerKey
(
encrypted
)
{
var
key
=
cryptojs
.
enc
.
Utf8
.
parse
(
process
.
env
.
AESKEY
);
var
options
=
{
mode
:
cryptojs
.
mode
.
CBC
,
padding
:
cryptojs
.
pad
.
Pkcs7
,
iv
:
cryptojs
.
enc
.
Utf8
.
parse
(
process
.
env
.
AESKEY
),
};
var
decrypted
=
cryptojs
.
AES
.
decrypt
(
encrypted
,
key
,
options
).
toString
(
cryptojs
.
enc
.
Utf8
);
return
decrypted
;
}
module
.
exports
=
DecryptWithServerKey
;
ExpressBackend/services/encryptionservice.js
View file @
3b425031
const
cryptojs
=
require
(
"
crypto-js
"
);
require
(
"
dotenv
"
).
config
();
function
EncryptWithServerKey
(
originalTxt
)
{
var
key
=
cryptojs
.
enc
.
Utf8
.
parse
(
process
.
env
.
AESKEY
);
var
options
=
{
mode
:
cryptojs
.
mode
.
CBC
,
padding
:
cryptojs
.
pad
.
Pkcs7
,
iv
:
cryptojs
.
enc
.
Utf8
.
parse
(
process
.
env
.
AESKEY
),
};
var
encryptedTxt
=
cryptojs
.
AES
.
encrypt
(
originalTxt
,
key
,
options
).
toString
();
return
encryptedTxt
;
}
function
EncryptWithStellarSeed
(
originalText
,
seed
)
{
var
key
=
cryptojs
.
enc
.
Utf8
.
parse
(
seed
);
var
options
=
{
mode
:
cryptojs
.
mode
.
CBC
,
padding
:
cryptojs
.
pad
.
Pkcs7
,
iv
:
cryptojs
.
enc
.
Utf8
.
parse
(
seed
),
};
var
encryptedTxt
=
cryptojs
.
AES
.
encrypt
(
originalText
,
key
,
options
).
toString
();
return
encryptedTxt
;
}
module
.
exports
=
{
EncryptWithServerKey
,
EncryptWithStellarSeed
};
ExpressBackend/services/stellarservice.js
deleted
100644 → 0
View file @
02330adc
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