Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Auth_Network

This is a school project for Cryptography teached by Dr.Nguyen Tan Khoi at Danang University of Science and Technology.

Implement a hyperledger fabric network named Asset Authentication Network

# Prerequisites:
- Ubuntu 18
- Docker, docker compose
- npm, node
- Go
- Hyperledger Fabric Binaries and docker images
-> they have to be added into linux path

# Run:
1. Delete all old cryptographic file in api 1.4
2. Regenerate all crypto material in artifact by rerunning artifacts/channel/create-artifacts.sh
3. Start the network by running start.sh
4. Start the api server by running "node api-1.4/app.js"

# Interact with the api server using these endpoints:
1. Import this collection of endpoint using Postman: https://www.getpostman.com/collections/401b1a02ed1330385449
2. Config your collection variable to suitable values.
3. First to register a user to get an access token.
4. Use that access token to trigger all other endpoints.

# Features:
1. Create,
2. Manage ownership,
3. and delete an ownership.
85 changes: 48 additions & 37 deletions api-1.4/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,17 +293,17 @@ app.post('/channels/:channelName/chaincodes/:chaincodeName', async function (req


const response_payload = {
result: message,
error: null,
errorData: null
"result": message,
"error": null,
"errorData": null
}
res.send(response_payload);

} catch (error) {
const response_payload = {
result: null,
error: error.name,
errorData: error.message
"result": null,
"error": error.name,
"errorData": error.message
}
res.send(response_payload)
}
Expand All @@ -312,40 +312,51 @@ app.post('/channels/:channelName/chaincodes/:chaincodeName', async function (req

// Query on chaincode on target peers
app.get('/channels/:channelName/chaincodes/:chaincodeName', async function (req, res) {
logger.debug('==================== QUERY BY CHAINCODE ==================');
var channelName = req.params.channelName;
var chaincodeName = req.params.chaincodeName;
let args = req.query.args;
let fcn = req.query.fcn;
let peer = req.query.peer;
try {
logger.debug('==================== QUERY BY CHAINCODE ==================');
var channelName = req.params.channelName;
var chaincodeName = req.params.chaincodeName;
let args = req.query.args;
let fcn = req.query.fcn;
let peer = req.query.peer;

logger.debug('channelName : ' + channelName);
logger.debug('chaincodeName : ' + chaincodeName);
logger.debug('fcn : ' + fcn);
logger.debug('args : ' + args);
logger.debug('channelName : ' + channelName);
logger.debug('chaincodeName : ' + chaincodeName);
logger.debug('fcn : ' + fcn);
logger.debug('args : ' + args);

if (!chaincodeName) {
res.json(getErrorMessage('\'chaincodeName\''));
return;
}
if (!channelName) {
res.json(getErrorMessage('\'channelName\''));
return;
}
if (!fcn) {
res.json(getErrorMessage('\'fcn\''));
return;
}
if (!args) {
res.json(getErrorMessage('\'args\''));
return;
}
args = args.replace(/'/g, '"');
args = JSON.parse(args);
logger.debug(args);
if (!chaincodeName) {
res.json(getErrorMessage('\'chaincodeName\''));
return;
}
if (!channelName) {
res.json(getErrorMessage('\'channelName\''));
return;
}
if (!fcn) {
res.json(getErrorMessage('\'fcn\''));
return;
}
if (!args) {
res.json(getErrorMessage('\'args\''));
return;
}
args = args.replace(/'/g, '"');
args = JSON.parse(args);
logger.debug(args);

let message = await query.queryChaincode(peer, channelName, chaincodeName, args, fcn, req.username, req.orgname);
res.send(message);

let message = await query.queryChaincode(peer, channelName, chaincodeName, args, fcn, req.username, req.orgname);
res.send(message);

} catch (error) {
const response_payload = {
result: null,
error: error.name,
errorData: error.message
}
res.send(response_payload)
}
});

// Query Get Block by BlockNumber
Expand Down
2 changes: 1 addition & 1 deletion api-1.4/app/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var getRegisteredUser = async function (username, userOrg, isJson) {
let caClient = client.getCertificateAuthority();
let secret = await caClient.register({
enrollmentID: username,
affiliation: userOrg.toLowerCase() + '.department1',
// affiliation: userOrg.toLowerCase() + '.department1',
attrs: [{ name: 'role', value: 'approver', ecert: true }]
}, adminUserObj);
// let secret = await caClient.register({
Expand Down
2 changes: 1 addition & 1 deletion api-1.4/app/invoke-transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ var invokeChaincode = async function (peerNames, channelName, chaincodeName, fcn
org_name, channelName, tx_id_string);
logger.info(message);

return { "tx_id": tx_id_string };
return { "tx_id": tx_id_string};
} else {
let message = util.format('Failed to invoke chaincode. cause:%s', error_message);
logger.error(message);
Expand Down
10 changes: 5 additions & 5 deletions api-1.4/artifacts/org1.yaml → api-1.4/artifacts/firm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# blockchain network that are necessary for the applications to interact with it. These are all
# knowledge that must be acquired from out-of-band sources. This file provides such a source.
#
name: "basic-network-org1"
name: "basic-network-firm"

#
# Any properties with an "x-" prefix will be treated as application-specific, exactly like how naming
Expand All @@ -19,7 +19,7 @@ x-type: "hlfv1"
#
# Describe what the target network is/does.
#
description: "Basic Network - client definition for Org1"
description: "Basic Network - client definition for Firm"

#
# Schema version of the content. Used by the SDK to apply the corresponding parsing rules.
Expand All @@ -32,22 +32,22 @@ version: "1.0"
client:
# Which organization does this application instance belong to? The value must be the name of an org
# defined under "organizations"
organization: Org1
organization: Firm

# Some SDKs support pluggable KV stores, the properties under "credentialStore"
# are implementation specific
credentialStore:
# [Optional]. Specific to FileKeyValueStore.js or similar implementations in other SDKs. Can be others
# if using an alternative impl. For instance, CouchDBKeyValueStore.js would require an object
# here for properties like url, db name, etc.
path: "./fabric-client-kv-org1"
path: "./fabric-client-kv-firm"

# [Optional]. Specific to the CryptoSuite implementation. Software-based implementations like
# CryptoSuite_ECDSA_AES.js in node SDK requires a key store. PKCS#11 based implementations does
# not.
cryptoStore:
# Specific to the underlying KeyValueStore that backs the crypto key store.
path: "./crypto/org1"
path: "./crypto/firm"

# [Optional]. Specific to Composer environment
wallet: wallet-name
10 changes: 5 additions & 5 deletions api-1.4/artifacts/org2.yaml → api-1.4/artifacts/gov.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# blockchain network that are necessary for the applications to interact with it. These are all
# knowledge that must be acquired from out-of-band sources. This file provides such a source.
#
name: "basic-network-org2"
name: "basic-network-gov"

#
# Any properties with an "x-" prefix will be treated as application-specific, exactly like how naming
Expand All @@ -19,7 +19,7 @@ x-type: "hlfv1"
#
# Describe what the target network is/does.
#
description: "Basicr Network - client definition for Org2"
description: "Basicr Network - client definition for gov"

#
# Schema version of the content. Used by the SDK to apply the corresponding parsing rules.
Expand All @@ -32,22 +32,22 @@ version: "1.0"
client:
# Which organization does this application instance belong to? The value must be the name of an org
# defined under "organizations"
organization: Org2
organization: Gov

# Some SDKs support pluggable KV stores, the properties under "credentialStore"
# are implementation specific
credentialStore:
# [Optional]. Specific to FileKeyValueStore.js or similar implementations in other SDKs. Can be others
# if using an alternative impl. For instance, CouchDBKeyValueStore.js would require an object
# here for properties like url, db name, etc.
path: "./fabric-client-kv-org2"
path: "./fabric-client-kv-gov"

# [Optional]. Specific to the CryptoSuite implementation. Software-based implementations like
# CryptoSuite_ECDSA_AES.js in node SDK requires a key store. PKCS#11 based implementations does
# not.
cryptoStore:
# Specific to the underlying KeyValueStore that backs the crypto key store.
path: "./crypto/org2"
path: "./crypto/gov"

# [Optional]. Specific to Composer environment
wallet: wallet-name
Loading