diff --git a/hyperledger_fabric/test/cc-install.sh b/hyperledger_fabric/test/cc-install.sh deleted file mode 100644 index 68a3d272..00000000 --- a/hyperledger_fabric/test/cc-install.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash -# Install a chaincode -# Usage: ./script mspId peerAddr mspPath=${PWD}/msp-mspId name version path - -# Entry function -main() { - if [ $# -lt 5 ]; then - echo "Not enough argument supplied" - echo "$(basename $0) mspId peerAddr mspPath=${PWD}/msp-mspId name version path" - exit 1 - fi - - local mspId=$1 - local peerAddr=$2 - local mspPath=${3:-${PWD}/msp-${mspId}} # Suppose the local msp path named as msp-${msp_id} - local name=$4 - local version=$5 - local path=$6 - local lang="golang" - - export FABRIC_LOGGING_SPEC="debug" - export CORE_PEER_ADDRESS="${peerAddr}" - export CORE_PEER_LOCALMSPID=${mspId} - export CORE_PEER_MSPCONFIGPATH=${mspPath} - export CORE_PEER_TLS_ROOTCERT_FILE=${mspPath}/tlscacerts/tlsca.cert - export CORE_PEER_TLS_ENABLED=true - - #export GRPC_GO_REQUIRE_HANDSHAKE=off - - peer chaincode install \ - -n ${name} \ - -v $version \ - -p ${path} \ - -l ${lang} \ - --peerAddresses "${peerAddr}" \ - --tlsRootCertFiles "${CORE_PEER_TLS_ROOTCERT_FILE}" - - exit 0 -} - -main "$@" \ No newline at end of file diff --git a/hyperledger_fabric/test/cc-list.sh b/hyperledger_fabric/test/cc-list-installed.sh similarity index 84% rename from hyperledger_fabric/test/cc-list.sh rename to hyperledger_fabric/test/cc-list-installed.sh index b3ad7140..c82838cc 100644 --- a/hyperledger_fabric/test/cc-list.sh +++ b/hyperledger_fabric/test/cc-list-installed.sh @@ -29,6 +29,12 @@ main() { --peerAddresses "${peerAddr}" \ --tlsRootCertFiles "${CORE_PEER_TLS_ROOTCERT_FILE}" + peer chaincode list \ + --connTimeout=30s \ + --instantiated \ + --peerAddresses "${peerAddr}" \ + --tlsRootCertFiles "${CORE_PEER_TLS_ROOTCERT_FILE}" + exit 0 } diff --git a/hyperledger_fabric/test/cc-discover.sh b/hyperledger_fabric/test/discover.sh similarity index 100% rename from hyperledger_fabric/test/cc-discover.sh rename to hyperledger_fabric/test/discover.sh diff --git a/hyperledger_fabric/test/getChaincode.sh b/hyperledger_fabric/test/getChaincode.sh deleted file mode 100644 index 92dbc82c..00000000 --- a/hyperledger_fabric/test/getChaincode.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/bash -# Fetch a config block and decode it - -setupChaincode() { - local channel=$1 - local peerAddresses=$2 - local tlsca_file=$3 - - peer chaincode instantiate \ - -o "dhnodeouf5-bcsnativepreprod-iad.blockchain.ocp.oc-test.com:20003" \ - -C ${channel} \ - -n "exp02" \ - -v "v1" \ - -c '{"Args":["init","a","100","b","200"]}' \ - -P "OR ('dhnodeOUf5.peer','dhnodeOUf6.peer')" \ - --tls \ - --cafile ${tlsca_file} \ - --peerAddresses ${peerAddresses} \ - --tlsRootCertFiles ${tlsca_file} -} - -# getInstantiatedChaincode get the instantiated chaincode information -# Usage: getInstantiatedChaincode channel peer-addresses -getInstantiatedChaincode() { - local channel=$1 - local peerAddresses=$2 - local tlsca_file=$3 - - peer chaincode query \ - --connTimeout 10s \ - --channelID ${channel} \ - -n "lscc" \ - -c '{"Args":["getccdata","default","c040953"]}' \ - --tls \ - --peerAddresses ${peerAddresses} \ - --tlsRootCertFiles ${tlsca_file} -} - -if [ $# -eq 0 ]; then - echo "Please use the as the argument" - exit -fi - -msp_id=$1 -channel=$2 -peerAddresses=$3 - -echo "msp_id=${msp_id}" -echo "channel=${channel}" -echo "peerAddresses=${peerAddresses}" - -msp_path=${PWD}/msp-${msp_id} # Suppose the local msp path named as msp-${msp_id} - -export FABRIC_LOGGING_SPEC="debug" -export CORE_PEER_LOCALMSPID=${msp_id} -#export CORE_PEER_ADDRESS=${peerAddresses} -export CORE_PEER_MSPCONFIGPATH=${msp_path} -export CORE_PEER_TLS_ROOTCERT_FILE=${msp_path}/tlscacerts/tlsca.cert -export CORE_PEER_TLS_ENABLED=true - -setupChaincode ${channel} ${peerAddresses} ${msp_path}/tlscacerts/tlsca.cert -#getInstantiatedChaincode ${channel} ${peerAddresses} ${msp_path}/tlscacerts/tlsca.cert diff --git a/hyperledger_fabric/v2.2.1/gateway-java/wallet/admin.id b/hyperledger_fabric/v2.2.1/gateway-java/wallet/admin.id new file mode 100644 index 00000000..7f2aaf26 --- /dev/null +++ b/hyperledger_fabric/v2.2.1/gateway-java/wallet/admin.id @@ -0,0 +1 @@ +{"credentials":{"certificate":"-----BEGIN CERTIFICATE-----\nMIICKDCCAc+gAwIBAgIQSdBFJUgRkBhzmW9htYh+UjAKBggqhkjOPQQDAjBzMQsw\nCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy\nYW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEcMBoGA1UEAxMTY2Eu\nb3JnMS5leGFtcGxlLmNvbTAeFw0yMDA3MTcxODE5MDBaFw0zMDA3MTUxODE5MDBa\nMGsxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1T\nYW4gRnJhbmNpc2NvMQ4wDAYDVQQLEwVhZG1pbjEfMB0GA1UEAwwWQWRtaW5Ab3Jn\nMS5leGFtcGxlLmNvbTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABJ2unYyG7FEY\n9oSq2tgtR7AMc0tto36cbwsLHEQ6aVPPwZAjkuTij6MpQxMf8gfLlw6cdBA898bG\nrL2DlttnwM6jTTBLMA4GA1UdDwEB/wQEAwIHgDAMBgNVHRMBAf8EAjAAMCsGA1Ud\nIwQkMCKAIKqf36g/sCvMlxb5pAHInL/lz2U6RJfYRzgbC38Wrp5QMAoGCCqGSM49\nBAMCA0cAMEQCIBL+/AwRBeh13pl+cY8ZlcJsNPDXPDc41wKKche8zdSSAiB5i5Lu\n+1Tnoy4T4l3DSf2K8xrx9UgFNn73kGfpYR12UQ==\n-----END CERTIFICATE-----","privateKey":"-----BEGIN PRIVATE KEY-----\r\nMIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg4ui7zz4MlrLCpncs\r\nYHdQQS6qp8M5JE3f8ZowaU+BBfahRANCAASdrp2MhuxRGPaEqtrYLUewDHNLbaN+\r\nnG8LCxxEOmlTz8GQI5Lk4o+jKUMTH/IHy5cOnHQQPPfGxqy9g5bbZ8DO\r\n-----END PRIVATE KEY-----"},"mspId":"Org1MSP","type":"X.509","version":1} \ No newline at end of file diff --git a/hyperledger_fabric/v2.2.1/test/connection-profile.json b/hyperledger_fabric/v2.2.1/sdk-node/connection-profile.json similarity index 100% rename from hyperledger_fabric/v2.2.1/test/connection-profile.json rename to hyperledger_fabric/v2.2.1/sdk-node/connection-profile.json diff --git a/hyperledger_fabric/v2.2.1/sdk-node/createWallet.js b/hyperledger_fabric/v2.2.1/sdk-node/createWallet.js new file mode 100644 index 00000000..7a4aaf1f --- /dev/null +++ b/hyperledger_fabric/v2.2.1/sdk-node/createWallet.js @@ -0,0 +1,65 @@ +"use strict"; + +const fs = require('fs'); +const path = require('path'); +const User = require('fabric-common/lib/User'); +const Signer = require('fabric-common/lib/Signer'); +const Utils = require('fabric-common/lib/Utils'); +const {common: commonProto} = require('fabric-protos'); +const {Wallets} = require('fabric-network'); + +const mspId = 'Org1MSP'; +const baseMSPPath='../crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp' +const signCertPath = path.resolve(baseMSPPath+'/signcerts/Admin@org1.example.com-cert.pem'); +const signKeyPath = path.resolve(baseMSPPath+'/keystore/priv_sk'); + +const signCert = fs.readFileSync(signCertPath).toString(); +const signKey = fs.readFileSync(signKeyPath).toString(); + +class gwSigningIdentity { + constructor(signingIdentity) { + this.type = 'X.509'; + this.mspId = signingIdentity._mspId; + this.credentials = { + certificate: signingIdentity._certificate.toString().trim(), + privateKey: signingIdentity._signer._key.toBytes().trim(), + }; + } +} + +/** + * Main entrance method + * @returns {Promise<*>} + */ +const main = async () => { + const user = loadUser('testAdmin', signCert, signKey); + const identity = new gwSigningIdentity(user._signingIdentity); + const wallet = await Wallets.newFileSystemWallet('/opt/test/wallet'); + await wallet.put(mspId+'-admin', identity); + return "wallet is created" +}; + +/** + * Construct a user object based on given cert and key strings + * @param {string} name Name to assign to the user + * @param {string} signCert Certificate string to sign + * @param {string} signKey Private key string to sign + * @returns {User} User object + */ +const loadUser = (name, signCert, signKey) => { + const SigningIdentity = require('fabric-common/lib/SigningIdentity'); + const user = new User(name); + user._cryptoSuite = Utils.newCryptoSuite(); + const privateKey = user._cryptoSuite.createKeyFromRaw(signKey); + const {_cryptoSuite} = user; + const pubKey = _cryptoSuite.createKeyFromRaw(signCert); + user._signingIdentity = new SigningIdentity(signCert, pubKey, mspId, _cryptoSuite, new Signer(_cryptoSuite, privateKey)); + user.getIdentity = () => { + return user._signingIdentity; + }; + return user; +}; + +main() + .then(console.log) + .catch(console.error); diff --git a/hyperledger_fabric/v2.2.1/test/getBlockchainInfo.js b/hyperledger_fabric/v2.2.1/sdk-node/getBlockchainInfo.js similarity index 95% rename from hyperledger_fabric/v2.2.1/test/getBlockchainInfo.js rename to hyperledger_fabric/v2.2.1/sdk-node/getBlockchainInfo.js index 53ed5077..bdcf8784 100644 --- a/hyperledger_fabric/v2.2.1/test/getBlockchainInfo.js +++ b/hyperledger_fabric/v2.2.1/sdk-node/getBlockchainInfo.js @@ -8,7 +8,7 @@ const User = require('fabric-common/lib/User'); const Signer = require('fabric-common/lib/Signer'); const Utils = require('fabric-common/lib/Utils'); const {common: commonProto} = require('fabric-protos'); -const {Gateway} = require('fabric-network'); +const {Gateway, Wallets} = require('fabric-network'); const IdentityContext = require('fabric-common/lib/IdentityContext'); const mspId = 'Org1MSP'; @@ -92,6 +92,10 @@ const callChaincode = async (channelName, chaincodeId, fcn, args, endorser, user gateWay.identity = identity; gateWay.identityContext = new IdentityContext(user, client); + // test wallet, safe to remove following 2 lines + //const wallet = await Wallets.newFileSystemWallet('/opt/test/wallet'); + //await wallet.put('org1admin', identity); + const channel = client.newChannel(channelName); client.channels.set(channelName, channel); channel.getEndorsers = () => Array.from(channel.endorsers.values()); @@ -104,6 +108,7 @@ const callChaincode = async (channelName, chaincodeId, fcn, args, endorser, user const network = await gateWay.getNetwork(channelName); const contract = network.getContract(chaincodeId); const tx = contract.createTransaction(fcn); + //const response = contract.evaluateTransaction(fcn, args) return tx.evaluate(...args); } diff --git a/hyperledger_fabric/v2.2.1/test/package-lock.json b/hyperledger_fabric/v2.2.1/sdk-node/package-lock.json similarity index 100% rename from hyperledger_fabric/v2.2.1/test/package-lock.json rename to hyperledger_fabric/v2.2.1/sdk-node/package-lock.json diff --git a/hyperledger_fabric/v2.2.1/test/package.json b/hyperledger_fabric/v2.2.1/sdk-node/package.json similarity index 100% rename from hyperledger_fabric/v2.2.1/test/package.json rename to hyperledger_fabric/v2.2.1/sdk-node/package.json diff --git a/hyperledger_fabric/v2.2.1/sdk-node/queryChaincode.js b/hyperledger_fabric/v2.2.1/sdk-node/queryChaincode.js new file mode 100644 index 00000000..49f8e88c --- /dev/null +++ b/hyperledger_fabric/v2.2.1/sdk-node/queryChaincode.js @@ -0,0 +1,155 @@ +"use strict"; + +const fs = require('fs'); +const path = require('path'); +const {Endorser, Endpoint, Discoverer} = require('fabric-common'); +const Client = require('fabric-common/lib/Client'); +const User = require('fabric-common/lib/User'); +const Signer = require('fabric-common/lib/Signer'); +const Utils = require('fabric-common/lib/Utils'); +const {common: commonProto} = require('fabric-protos'); +const {Gateway} = require('fabric-network'); +const IdentityContext = require('fabric-common/lib/IdentityContext'); + +const mspId = 'Org1MSP'; +const peerURL = `grpcs://peer1.org1.example.com:7051`; +const channelName = 'businesschannel'; +const baseMSPPath='../crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp' +const tlsCAPath = path.resolve(baseMSPPath+'/tlscacerts/tlsca.org1.example.com-cert.pem'); +const signCertPath = path.resolve(baseMSPPath+'/signcerts/Admin@org1.example.com-cert.pem'); +const signKeyPath = path.resolve(baseMSPPath+'/keystore/priv_sk'); + +const chaincodeId = 'exp02'; +const fcn = 'query'; +const args = ['a']; + +const tlsCACert = fs.readFileSync(tlsCAPath).toString(); +const signCert = fs.readFileSync(signCertPath).toString(); +const signKey = fs.readFileSync(signKeyPath).toString(); + +class gwSigningIdentity { + constructor(signingIdentity) { + this.type = 'X.509'; + this.mspId = signingIdentity._mspId; + this.credentials = { + certificate: signingIdentity._certificate.toString().trim(), + privateKey: signingIdentity._signer._key.toBytes().trim(), + }; + } +} + +/** + * Main entrance method + * @returns {Promise<*>} + */ +const main = async () => { + const options = { + url: peerURL, + 'grpc-wait-for-ready-timeout': 30000, + pem: tlsCACert + //'grpc.ssl_target_name_override': peerHost + }; + const endpoint = new Endpoint(options); + const endorser = new Endorser('myEndorser', {}, mspId); + endorser.setEndpoint(endpoint); + await endorser.connect(); + + // Only for test purpose, safe to remove following 3 lines + const discoverer = new Discoverer('myDiscoverer', {}, mspId); + discoverer.setEndpoint(endpoint); + await discoverer.connect(); + + const user = loadUser('test-Admin', signCert, signKey); + //---- query on chaincode + return queryChaincode(channelName, chaincodeId, fcn, args, endorser, user) + +}; + +/** + * Get the blockchain info from given channel + * @param {string} channelName Channel to fetch blockchain info + * @param {string} chaincodeId Id of the chaincode + * @param {string} fcn Chaincode method to call + * @param {array} args Chaincode method arguments + * @param {Endorser} endorser Endorser to send the request to + * @param {User} user Identity to use + * @returns {BlockchainInfo} Parsed blockchain info struct + */ +const queryChaincode = async (channelName,chaincodeId, fcn, args, endorser, user) => { + let result = await callChaincode(channelName, chaincodeId, fcn, args, endorser, user) + return parseQueryResponse(result) +} + +/** + * Call a chaincode and return the response in raw proto + * @param {string} channelName Name of the channel + * @param {string} chaincodeId Name of the chaincode + * @param {string} fcn Name of the chaincode method to call + * @param {string} args Parameters for the Chaincode method + * @param {Endorser} endorser Endorser to send the request to + * @param {User} user Identity to use + * @returns {Promise} + */ +const callChaincode = async (channelName, chaincodeId, fcn, args, endorser, user) => { + const gateWay = new Gateway(); + const client = new Client(null); + const identity = new gwSigningIdentity(user._signingIdentity); + gateWay.identity = identity; + gateWay.identityContext = new IdentityContext(user, client); + + const channel = client.newChannel(channelName); + client.channels.set(channelName, channel); + channel.getEndorsers = () => Array.from(channel.endorsers.values()); + channel.endorsers.set(endorser.toString(), endorser); + + await gateWay.connect(client, { + wallet: {}, discovery: {enabled: false}, identity + }); + + const network = await gateWay.getNetwork(channelName); + const contract = network.getContract(chaincodeId); + const tx = contract.createTransaction(fcn); + //const response = contract.evaluateTransaction(fcn, args) + + return tx.evaluate(...args); +} + +/** + * Parse the result into the blockchain info structure + * @param {Buffer} _resultProto The original result from fabric network + * @returns {{previousBlockHash: string, currentBlockHash: string, height: number}} + */ + +/** + * Parse the query result + * @param _resultProto + * @returns {string} + */ +const parseQueryResponse = (_resultProto) => { + return _resultProto.toString() +}; + +/** + * Construct a user object based on given cert and key strings + * @param {string} name Name to assign to the user + * @param {string} signCert Certificate string to sign + * @param {string} signKey Private key string to sign + * @returns {User} User object + */ +const loadUser = (name, signCert, signKey) => { + const SigningIdentity = require('fabric-common/lib/SigningIdentity'); + const user = new User(name); + user._cryptoSuite = Utils.newCryptoSuite(); + const privateKey = user._cryptoSuite.createKeyFromRaw(signKey); + const {_cryptoSuite} = user; + const pubKey = _cryptoSuite.createKeyFromRaw(signCert); + user._signingIdentity = new SigningIdentity(signCert, pubKey, mspId, _cryptoSuite, new Signer(_cryptoSuite, privateKey)); + user.getIdentity = () => { + return user._signingIdentity; + }; + return user; +}; + +main() + .then(console.log) + .catch(console.error); diff --git a/hyperledger_fabric/v2.2.1/test/sample-gateway.js b/hyperledger_fabric/v2.2.1/sdk-node/sample-gateway.js similarity index 100% rename from hyperledger_fabric/v2.2.1/test/sample-gateway.js rename to hyperledger_fabric/v2.2.1/sdk-node/sample-gateway.js diff --git a/hyperledger_fabric/v2.2.1/test/simple.js b/hyperledger_fabric/v2.2.1/test/simple.js deleted file mode 100644 index 18e5d44a..00000000 --- a/hyperledger_fabric/v2.2.1/test/simple.js +++ /dev/null @@ -1,30 +0,0 @@ -'use strict'; - -const fs = require('fs') - -const {Gateway, gatewayOptions} = require('fabric-network'); - -async function main() { - -// read a common connection profile in json format - const data = fs.readFileSync('/opt/test/connection-profile.json'); - const connectionProfile = JSON.parse(data); - - const user = - { - credentials: { - certificate: '-----BEGIN CERTIFICATE-----MIICKDCCAc+gAwIBAgIQSdBFJUgRkBhzmW9htYh+UjAKBggqhkjOPQQDAjBzMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEcMBoGA1UEAxMTY2Eub3JnMS5leGFtcGxlLmNvbTAeFw0yMDA3MTcxODE5MDBaFw0zMDA3MTUxODE5MDBaMGsxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1TYW4gRnJhbmNpc2NvMQ4wDAYDVQQLEwVhZG1pbjEfMB0GA1UEAwwWQWRtaW5Ab3JnMS5leGFtcGxlLmNvbTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABJ2unYyG7FEY9oSq2tgtR7AMc0tto36cbwsLHEQ6aVPPwZAjkuTij6MpQxMf8gfLlw6cdBA898bGrL2DlttnwM6jTTBLMA4GA1UdDwEB/wQEAwIHgDAMBgNVHRMBAf8EAjAAMCsGA1UdIwQkMCKAIKqf36g/sCvMlxb5pAHInL/lz2U6RJfYRzgbC38Wrp5QMAoGCCqGSM49BAMCA0cAMEQCIBL+/AwRBeh13pl+cY8ZlcJsNPDXPDc41wKKche8zdSSAiB5i5Lu+1Tnoy4T4l3DSf2K8xrx9UgFNn73kGfpYR12UQ==-----END CERTIFICATE-----', - privateKey: '-----BEGIN PRIVATE KEY-----MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg4ui7zz4MlrLCpncsYHdQQS6qp8M5JE3f8ZowaU+BBfahRANCAASdrp2MhuxRGPaEqtrYLUewDHNLbaN+nG8LCxxEOmlTz8GQI5Lk4o+jKUMTH/IHy5cOnHQQPPfGxqy9g5bbZ8DO-----END PRIVATE KEY-----', - }, - mspId: 'Org1MSP', - type: 'X.509', -}; - -// use the loaded connection profile - const gateway = new Gateway(); - await gateway.connect(connectionProfile, { identity: user}); - - const network = await gateway.getNetwork('businesschannel'); -} - -main() \ No newline at end of file diff --git a/hyperledger_fabric/v2.2.1/test/simple1.js b/hyperledger_fabric/v2.2.1/test/simple1.js deleted file mode 100644 index 4c04cce8..00000000 --- a/hyperledger_fabric/v2.2.1/test/simple1.js +++ /dev/null @@ -1,43 +0,0 @@ -'use strict'; - -const fs = require('fs') - -//const {Gateway} = require('fabric-network'); -const {Client, Endorser, Endpoint} = require('fabric-common'); - -async function main() { - -// read a common connection profile in json format - const data = fs.readFileSync('/opt/test/connection-profile.json'); - const connectionProfile = JSON.parse(data); - - const user = - { - credentials: { - certificate: '-----BEGIN CERTIFICATE-----MIICKDCCAc+gAwIBAgIQSdBFJUgRkBhzmW9htYh+UjAKBggqhkjOPQQDAjBzMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEcMBoGA1UEAxMTY2Eub3JnMS5leGFtcGxlLmNvbTAeFw0yMDA3MTcxODE5MDBaFw0zMDA3MTUxODE5MDBaMGsxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1TYW4gRnJhbmNpc2NvMQ4wDAYDVQQLEwVhZG1pbjEfMB0GA1UEAwwWQWRtaW5Ab3JnMS5leGFtcGxlLmNvbTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABJ2unYyG7FEY9oSq2tgtR7AMc0tto36cbwsLHEQ6aVPPwZAjkuTij6MpQxMf8gfLlw6cdBA898bGrL2DlttnwM6jTTBLMA4GA1UdDwEB/wQEAwIHgDAMBgNVHRMBAf8EAjAAMCsGA1UdIwQkMCKAIKqf36g/sCvMlxb5pAHInL/lz2U6RJfYRzgbC38Wrp5QMAoGCCqGSM49BAMCA0cAMEQCIBL+/AwRBeh13pl+cY8ZlcJsNPDXPDc41wKKche8zdSSAiB5i5Lu+1Tnoy4T4l3DSf2K8xrx9UgFNn73kGfpYR12UQ==-----END CERTIFICATE-----', - privateKey: '-----BEGIN PRIVATE KEY-----MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg4ui7zz4MlrLCpncsYHdQQS6qp8M5JE3f8ZowaU+BBfahRANCAASdrp2MhuxRGPaEqtrYLUewDHNLbaN+nG8LCxxEOmlTz8GQI5Lk4o+jKUMTH/IHy5cOnHQQPPfGxqy9g5bbZ8DO-----END PRIVATE KEY-----', - }, - mspId: 'org1MSP', - type: 'X.509', -}; - - const client = new Client("c1") - client.addTlsClientCertAndKey({ - url: "grpcs://peer1.org1.example.com:7051", - pem: "-----BEGIN CERTIFICATE----- MIICVzCCAf2gAwIBAgIQQaMCImEphSvSI+GHAJmxqjAKBggqhkjOPQQDAjB2MQsw CQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEfMB0GA1UEAxMWdGxz Y2Eub3JnMS5leGFtcGxlLmNvbTAeFw0yMDA3MTcxODE5MDBaFw0zMDA3MTUxODE5MDBaMHYxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQH Ew1TYW4gRnJhbmNpc2NvMRkwFwYDVQQKExBvcmcxLmV4YW1wbGUuY29tMR8wHQYDVQQDExZ0bHNjYS5vcmcxLmV4YW1wbGUuY29tMFkwEwYHKoZIzj0CAQYIKoZIzj0D AQcDQgAEVmrLLrpumifDP5gJfjVK3+RPl2W67+7NS/CV0rRfCG8d4xx+QvCRlaW/3LyIpcBMfGe7G9UgiaIVhhYHh+eNXKNtMGswDgYDVR0PAQH/BAQDAgGmMB0GA1Ud JQQWMBQGCCsGAQUFBwMCBggrBgEFBQcDATAPBgNVHRMBAf8EBTADAQH/MCkGA1UdDgQiBCAw6bXoQrmlIxGxtNMGQ0Vm+MGt3WFBoRP5kADb3O+TEjAKBggqhkjOPQQD AgNIADBFAiBkhGF4Adl6z0QfQlcAM85D2yFPVzC3/9WMJo/Qtjil9QIhAOfrSbTlIlN1ytBONKWl30rCv0pFOd6nTN7BOwllhWZq -----END CERTIFICATE-----", - clientKey:"-----BEGIN PRIVATE KEY-----MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgOQEb55wiTX74p7cAMi33at2kDn0hgN2Q9lWutWRjTm+hRANCAATZEXMExJbwUnRYm6Mha/hrjnXgbhLKLAkmwh9iFRrW1zWIxLbH+FLerQUWd/bveuhIS8koYab+3+a3twzYzwwx-----END PRIVATE KEY-----", - clientCert: "-----BEGIN CERTIFICATE-----MIICOzCCAeKgAwIBAgIRAPUP28xYwbLj0OAzFk4wlvgwCgYIKoZIzj0EAwIwdjELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBGcmFuY2lzY28xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHzAdBgNVBAMTFnRsc2NhLm9yZzEuZXhhbXBsZS5jb20wHhcNMjAwNzE3MTgxOTAwWhcNMzAwNzE1MTgxOTAwWjBbMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEfMB0GA1UEAwwWQWRtaW5Ab3JnMS5leGFtcGxlLmNvbTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABNkRcwTElvBSdFiboyFr+GuOdeBuEsosCSbCH2IVGtbXNYjEtsf4Ut6tBRZ39u966EhLyShhpv7f5re3DNjPDDGjbDBqMA4GA1UdDwEB/wQEAwIFoDAdBgNVHSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwDAYDVR0TAQH/BAIwADArBgNVHSMEJDAigCAw6bXoQrmlIxGxtNMGQ0Vm+MGt3WFBoRP5kADb3O+TEjAKBggqhkjOPQQDAgNHADBEAiAYQu0XAzDyrnlcJophUUV2HxnudmUGOXSLFONm4fa+6QIgRxeA7O1JDy9Yy2uM3aX5kNe9+WjSySGnp07ceLuRak4=-----END CERTIFICATE-----" - }) - client.setTlsClientCertAndKey("-----BEGIN CERTIFICATE-----MIICOzCCAeKgAwIBAgIRAPUP28xYwbLj0OAzFk4wlvgwCgYIKoZIzj0EAwIwdjELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBGcmFuY2lzY28xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHzAdBgNVBAMTFnRsc2NhLm9yZzEuZXhhbXBsZS5jb20wHhcNMjAwNzE3MTgxOTAwWhcNMzAwNzE1MTgxOTAwWjBbMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEfMB0GA1UEAwwWQWRtaW5Ab3JnMS5leGFtcGxlLmNvbTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABNkRcwTElvBSdFiboyFr+GuOdeBuEsosCSbCH2IVGtbXNYjEtsf4Ut6tBRZ39u966EhLyShhpv7f5re3DNjPDDGjbDBqMA4GA1UdDwEB/wQEAwIFoDAdBgNVHSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwDAYDVR0TAQH/BAIwADArBgNVHSMEJDAigCAw6bXoQrmlIxGxtNMGQ0Vm+MGt3WFBoRP5kADb3O+TEjAKBggqhkjOPQQDAgNHADBEAiAYQu0XAzDyrnlcJophUUV2HxnudmUGOXSLFONm4fa+6QIgRxeA7O1JDy9Yy2uM3aX5kNe9+WjSySGnp07ceLuRak4=-----END CERTIFICATE-----","-----BEGIN PRIVATE KEY-----MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgOQEb55wiTX74p7cAMi33at2kDn0hgN2Q9lWutWRjTm+hRANCAATZEXMExJbwUnRYm6Mha/hrjnXgbhLKLAkmwh9iFRrW1zWIxLbH+FLerQUWd/bveuhIS8koYab+3+a3twzYzwwx-----END PRIVATE KEY-----") - - const endPoint = new Endpoint({url:"grpcs://peer1.org1.example.com:7051", pem:"-----BEGIN CERTIFICATE----- MIICVzCCAf2gAwIBAgIQQaMCImEphSvSI+GHAJmxqjAKBggqhkjOPQQDAjB2MQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy YW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEfMB0GA1UEAxMWdGxzY2Eub3JnMS5leGFtcGxlLmNvbTAeFw0yMDA3MTcxODE5MDBaFw0zMDA3MTUxODE5 MDBaMHYxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1TYW4gRnJhbmNpc2NvMRkwFwYDVQQKExBvcmcxLmV4YW1wbGUuY29tMR8wHQYD VQQDExZ0bHNjYS5vcmcxLmV4YW1wbGUuY29tMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEVmrLLrpumifDP5gJfjVK3+RPl2W67+7NS/CV0rRfCG8d4xx+QvCRlaW/ 3LyIpcBMfGe7G9UgiaIVhhYHh+eNXKNtMGswDgYDVR0PAQH/BAQDAgGmMB0GA1UdJQQWMBQGCCsGAQUFBwMCBggrBgEFBQcDATAPBgNVHRMBAf8EBTADAQH/MCkGA1Ud DgQiBCAw6bXoQrmlIxGxtNMGQ0Vm+MGt3WFBoRP5kADb3O+TEjAKBggqhkjOPQQDAgNIADBFAiBkhGF4Adl6z0QfQlcAM85D2yFPVzC3/9WMJo/Qtjil9QIhAOfrSbTl IlN1ytBONKWl30rCv0pFOd6nTN7BOwllhWZq -----END CERTIFICATE-----", requestTimeout:30000}) - - const endorser = new Endorser("peer1-org1", client,"org1MSP") - await endorser.connect(endPoint) -// use the loaded connection profile - //const gateway = new Gateway(); - //await gateway.connect(connectionProfile, { identity: user}); - //const network = await gateway.getNetwork('businesschannel'); -} - -main() \ No newline at end of file diff --git a/hyperledger_fabric/v2.2.1/test/simple2.js b/hyperledger_fabric/v2.2.1/test/simple2.js deleted file mode 100644 index fd39a768..00000000 --- a/hyperledger_fabric/v2.2.1/test/simple2.js +++ /dev/null @@ -1,44 +0,0 @@ -'use strict'; - -const {Gateway, Wallets} = require('fabric-network'); -const path = require('path'); - -const connectionProfileFileName = '/opt/test/connection-profile.json' - -async function main() { -// Connect to a gateway peer - const connectionProfileJson = (await fs.promises.readFile(connectionProfileFileName)).toString(); - const connectionProfile = JSON.parse(connectionProfileJson); - const wallet = await Wallets.newFileSystemWallet(walletDirectoryPath); - const gatewayOptions: GatewayOptions = { - identity: 'user@example.org', // Previously imported identity - wallet, - }; - const gateway = new Gateway(); - await gateway.connect(connectionProfile, gatewayOptions); - - try { - - // Obtain the smart contract with which our application wants to interact - const network = await gateway.getNetwork(channelName); - const contract = network.getContract(chaincodeId); - - // Submit transactions for the smart contract - const args = [arg1, arg2]; - const submitResult = await contract.submitTransaction('transactionName', ...args); - - // Evaluate queries for the smart contract - const evalResult = await contract.evaluateTransaction('transactionName', ...args); - - // Create and submit transactions for the smart contract with transient data - const transientResult = await contract.createTransaction(transactionName) - .setTransient(privateData) - .submit(arg1, arg2); - - } finally { - // Disconnect from the gateway peer when all work for this client identity is complete - gateway.disconnect(); - } -} - -main()