Skip to content

Commit

Permalink
project completed
Browse files Browse the repository at this point in the history
  • Loading branch information
BIJOY-SUST committed Jan 30, 2020
1 parent e4fe90f commit 2ef7042
Show file tree
Hide file tree
Showing 248 changed files with 32,892 additions and 1,096 deletions.
1,340 changes: 797 additions & 543 deletions chaincode/fabcar/go/fabcar.go

Large diffs are not rendered by default.

1,092 changes: 1,004 additions & 88 deletions fabcar/javascript/app.js

Large diffs are not rendered by default.

57 changes: 57 additions & 0 deletions fabcar/javascript/key.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 'use strict';
// const ursa = require('ursa')
// const crypto = require('crypto')
// const path = require('path')
// const fs = require('fs')

// var keyPair = ursa.generatePrivateKey(1024, 65537);
// var privkeypem = keyPair.toPrivatePem();
// var pubkeypem = keyPair.toPublicPem();

// var privkeystr = privkeypem.toString('utf8');
// var pubkeystr = pubkeypem.toString('utf8');

// var name = 'saba'

// console.log(privkeystr);
// console.log(pubkeystr);

// var privateKeyObj = ursa.coercePrivateKey(privkeystr)
// console.log("Name :", name)
// var sign = keyPair.hashAndSign('sha256', name, 'utf8', 'base64');

// // Create public key object from PEM string
// var pub = ursa.createPublicKey(pubkeypem, 'base64');

// // Verify signature - should return true
// const bol =pub.hashAndVerify('sha256',name, sign);

// console.log(bol);

var ursa = require('ursa');

// Generate RSA private key (public key included)
var keyPair = ursa.generatePrivateKey();

// Convert public key to string
var pub = keyPair.toPublicPem('base64');
var privkeypem = keyPair.toPrivatePem();
var privStr = privkeypem.toString();
console.log(privStr)
var buf = new Buffer(privStr)

var jj =ursa.createPrivateKey(buf)
// Create buffer from text
var data = new Buffer('Hello, world!');

// Create MD5 hash and sign with private key
var sig = jj.hashAndSign('md5', data);

// Elsewhere...

// Create public key object from PEM string
pub = ursa.createPublicKey(pub, 'base64');

// Verify signature - should return true
var rr =pub.hashAndVerify('md5', data, sig);
console.log(rr)
22 changes: 22 additions & 0 deletions fabcar/javascript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion fabcar/javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"multer": "^1.4.2",
"mv": "^2.1.1",
"nodemon": "^1.19.4",
"path": "^0.12.7"
"path": "^0.12.7",
"ursa": "^0.9.4"
},
"devDependencies": {
"chai": "^4.2.0",
Expand Down
68 changes: 68 additions & 0 deletions fabcar/javascript/profileVerify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const crypto = require("crypto");
const path = require('path');
const fs = require('file-system');
var mv = require('mv');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
var multer = require('multer');
var detect = require('detect-file-type');
var upload = multer({ dest: './website/property/' });
var uploadFile = multer({ dest: './website/IntellectualProperty/' });

const profileInformation = require('./routers/profileInformation');
const topPeopleIP = require('./routers/topPeopleIP');


const profileVerify= async function (req, res) {

if (req.cookies.token === undefined) return {view: 'index',obj:undefined};
else {
var key = req.cookies.key;
var email = req.cookies.email;
var name = '';
var profilePic = '';
// console.log('Profile is loading : ' + email +" "+key);
await profileInformation(email, key).then((result) => {

var obj = JSON.parse(result);
// console.log(peopleList);
name = obj.name;
console.log('change '+ email+' '+name)
profilePic = obj.newFilePath;

console.log('Your profile pic retrieve from the blockchain');

}).catch((error) => {
console.log('View Profile Failed');
return {view:'index',obj:undefined}
});

await topPeopleIP(email).then((result) => {
console.log('now ready , the list is coming');
var postObj = JSON.parse(result);
// console.log(postObj);

var loveObj = postObj;
postObj.sort((a, b) => (a.Record.postCnt < b.Record.postCnt) ? 1 : -1);
var newPostObj = postObj.slice(0, 2); // 7

loveObj.sort((a, b) => (a.Record.loveCnt < b.Record.loveCnt) ? 1 : -1);
var newLoveObj = loveObj.slice(0, 3); // 8


return {view:'home', obj:{
'name': name,
'email': email,
'profilePic': profilePic,
'newPostObj': newPostObj,
'newLoveObj': newLoveObj
}
}
}
).catch((e) => {
console.log('Request Failed');
return {view:'index',obj:undefined}
});
}
}
module.exports = profileVerify
55 changes: 55 additions & 0 deletions fabcar/javascript/routers/addBalance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* eslint-disable no-unused-vars */
/*
* SPDX-License-Identifier: Apache-2.0
*/

'use strict';

const { FileSystemWallet, Gateway } = require('fabric-network');
const path = require('path');

const ccpPath = path.resolve(__dirname, '..', '..', '..', 'first-network', 'connection-org1.json');

async function main(email, userKey, price) {
try {

// Create a new file system based wallet for managing identities.
const walletPath = path.join(process.cwd(), 'wallet');
const wallet = new FileSystemWallet(walletPath);
console.log(`Wallet path(Add Balance of User): ${walletPath}`);

// Check to see if we've already enrolled the user.
const userExists = await wallet.exists(email);
if (!userExists) {
console.log('An identity for the user '+email+' does not exist in the wallet');
console.log('Run the registerUser.js application before retrying');
return;
}

// Create a new gateway for connecting to our peer node.
const gateway = new Gateway();
await gateway.connect(ccpPath, { wallet, identity: email, discovery: { enabled: true, asLocalhost: true } });

// Get the network (channel) our contract is deployed to.
const network = await gateway.getNetwork('mychannel');

// Get the contract from the network.
const contract = network.getContract('fabcar');

console.log(email + 'is getting money');
await contract.submitTransaction('addBalance', userKey, price);


console.log('Transaction of adding Balance has been submitted');

// Disconnect from the gateway.
await gateway.disconnect();

} catch (error) {
console.error(`Failed to submit transaction: ${error}`);
process.exit(1);
}
}

// main();
module.exports = main;
2 changes: 1 addition & 1 deletion fabcar/javascript/routers/allFriendPost.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async function main(email) {


} catch (error) {
console.error(`Failed to evaluate transaction: ${error}`);
console.error(`[allfriend post]Failed to evaluate transaction: ${error}`);
process.exit(1);
return error;
}
Expand Down
55 changes: 55 additions & 0 deletions fabcar/javascript/routers/changeOwner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* eslint-disable no-unused-vars */
/*
* SPDX-License-Identifier: Apache-2.0
*/

'use strict';

const { FileSystemWallet, Gateway } = require('fabric-network');
const path = require('path');

const ccpPath = path.resolve(__dirname, '..', '..', '..', 'first-network', 'connection-org1.json');

async function main(ipKey, userKey, name, email, dateTime,prevOwnerKey) {
try {

// Create a new file system based wallet for managing identities.
const walletPath = path.join(process.cwd(), 'wallet');
const wallet = new FileSystemWallet(walletPath);
console.log(`Wallet path(change ownership of IP): ${walletPath}`);

// Check to see if we've already enrolled the user.
const userExists = await wallet.exists(email);
if (!userExists) {
console.log('An identity for the user '+email+' does not exist in the wallet');
console.log('Run the registerUser.js application before retrying');
return;
}

// Create a new gateway for connecting to our peer node.
const gateway = new Gateway();
await gateway.connect(ccpPath, { wallet, identity: email, discovery: { enabled: true, asLocalhost: true } });

// Get the network (channel) our contract is deployed to.
const network = await gateway.getNetwork('mychannel');

// Get the contract from the network.
const contract = network.getContract('fabcar');

console.log(email + '"s IP is going to blockchain ');
await contract.submitTransaction('changeOwner', ipKey, userKey, name, email, dateTime,prevOwnerKey);


console.log('Transaction of IP ownership change has been submitted');

// Disconnect from the gateway.
await gateway.disconnect();

} catch (error) {
console.error(`Failed to submit transaction: ${error}`);
process.exit(1);
}
}

// main();
module.exports = main;
55 changes: 55 additions & 0 deletions fabcar/javascript/routers/changeRequestValidity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* eslint-disable no-unused-vars */
/*
* SPDX-License-Identifier: Apache-2.0
*/

'use strict';

const { FileSystemWallet, Gateway } = require('fabric-network');
const path = require('path');

const ccpPath = path.resolve(__dirname, '..', '..', '..', 'first-network', 'connection-org1.json');

async function main(email, key, isValid) {
try {

// Create a new file system based wallet for managing identities.
const walletPath = path.join(process.cwd(), 'wallet');
const wallet = new FileSystemWallet(walletPath);
console.log(`Wallet path(change validity): ${walletPath}`);

// Check to see if we've already enrolled the user.
const userExists = await wallet.exists(email);
if (!userExists) {
console.log('An identity for the user '+email+' does not exist in the wallet');
console.log('Run the registerUser.js application before retrying');
return;
}

// Create a new gateway for connecting to our peer node.
const gateway = new Gateway();
await gateway.connect(ccpPath, { wallet, identity: email, discovery: { enabled: true, asLocalhost: true } });

// Get the network (channel) our contract is deployed to.
const network = await gateway.getNetwork('mychannel');

// Get the contract from the network.
const contract = network.getContract('fabcar');

console.log(email + '"s validity change request is going to blockchain ');
await contract.submitTransaction('changeReq',key, isValid);


console.log('Transaction of request validity change has been submitted');

// Disconnect from the gateway.
await gateway.disconnect();

} catch (error) {
console.error(`Failed to submit transaction: ${error}`);
process.exit(1);
}
}

// main();
module.exports = main;
Loading

0 comments on commit 2ef7042

Please sign in to comment.