Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
TIC
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
BY
TIC
Commits
433569b7
Commit
433569b7
authored
Feb 10, 2021
by
anandhakumarpalanisamy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Added Node sdk test examples to interact with bityoga fabric set up
- Refer README for more instructions
parent
457a39fa
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
517 additions
and
0 deletions
+517
-0
.gitignore
fabric_node_sdk_tester/.gitignore
+1
-0
README.md
fabric_node_sdk_tester/README.md
+69
-0
enrollAdmin.js
fabric_node_sdk_tester/enrollAdmin.js
+59
-0
get_tls_certificates.sh
fabric_node_sdk_tester/get_tls_certificates.sh
+8
-0
tls-tlsca-7054.pem
...dk_tester/hlft-store/hlfMSP/tlscacerts/tls-tlsca-7054.pem
+13
-0
tls-tlsca-7054.pem
.../hlft-store/orderer/tls-msp/tlscacerts/tls-tlsca-7054.pem
+13
-0
tls-tlsca-7054.pem
...er/hlft-store/peer2/tls-msp/tlscacerts/tls-tlsca-7054.pem
+13
-0
invoke.js
fabric_node_sdk_tester/invoke.js
+76
-0
network_profile.json
fabric_node_sdk_tester/network_profile.json
+84
-0
package.json
fabric_node_sdk_tester/package.json
+42
-0
query.js
fabric_node_sdk_tester/query.js
+72
-0
registerUser.js
fabric_node_sdk_tester/registerUser.js
+67
-0
No files found.
fabric_node_sdk_tester/.gitignore
0 → 100644
View file @
433569b7
node_modules
fabric_node_sdk_tester/README.md
0 → 100644
View file @
433569b7
# Hyperledger Fabric NodeSDK Tester
Node sdk test examples to interact with bityoga fabric set up
# Requirements
1.
Bityoga fabric sdk should be up and running
2.
Node version
-
Supports node version >=8
-
Tested with v8.9.0
# Run Instructions
1.
## Clone this repository
-
git clone https://github.com/bityoga/fabric_node_sdk_tester.git
2.
## Run npm install
-
cd fabric_node_sdk_tester
-
#### Set node version
-
nvm use node v8.9.0 (using nvm)
-
npm install
3.
## Update ip address in 'network_profile.json'
-
update the url ip addresses of orderer, peer2, orgca, tlsca (4 places).
-
update it with your prime manager's ip address
4.
## Retrieve hyperledger fabric tls certificates of 'orderer' and 'peer2'
#### (Replace ip address with your fabric prime manager's ip address)
- scp -r root@178.62.207.235:/root/hlft-store/tlsca/orderer/tls-msp/tlscacerts/tls-tlsca-7054.pem ./hlft-store/tlsca/orderer/tls-msp/tlscacerts/tls-tlsca-7054.pem
- scp -r /root/hlft-store/tlsca/peer2/tls-msp/tlscacerts/tls-tlsca-7054.pem ./hlft-store/tlsca/peer2/tls-msp/tlscacerts/tls-tlsca-7054.pem
(or)
- run shell script **" bash get_tls_certificates.sh "**
5.
## Enroll admin
-
#### Command : node enrollAdmin.js
-
check wallet directory
-
a directory named 'admin' will be available
-
certificates for admin will be available under this directory.
6.
## Register user
-
If needed, edit the following lines in registerUser.js
-
const user_name = "lion";
-
const user_password = "lion";
-
const user_role = "client";
-
#### Command : node registerUser.js
-
check wallet directory
-
a directory with the name of the 'registerd user name' will be available
-
certificates for the registerd user will be available under this directory.
7.
## Query a chaincode
-
If needed, edit the following lines in query.js
-
const user_name = "lion";
-
const CHANNEL_NAME = "appchannel";
-
const CHAIN_CODE_NAME = "carcc";
-
const CHAIN_CODE_FUNCTION_NAME = "listCars";
-
const result = await contract.evaluateTransaction(CHAIN_CODE_FUNCTION_NAME);
-
const result = await contract.evaluateTransaction(CHAIN_CODE_FUNCTION_NAME,"b");
-
#### Command : node query.js
8.
## Invoke a chaincode
-
If needed, edit the following lines in invoke.js
-
const user_name = "lion";
-
const CHANNEL_NAME = "appchannel";
-
const CHAIN_CODE_NAME = "carcc";
-
const CHAIN_CODE_FUNCTION_NAME = "createCar";
-
await contract.submitTransaction(CHAIN_CODE_FUNCTION_NAME, "TR8800","Opel","Corsa","Light Blue","7","2050","1");
-
await contract.submitTransaction(CHAIN_CODE_FUNCTION_NAME, "b","a","1");
-
#### Command : node invoke.js
fabric_node_sdk_tester/enrollAdmin.js
0 → 100644
View file @
433569b7
/*
* SPDX-License-Identifier: Apache-2.0
*/
'use strict'
;
const
FabricCAServices
=
require
(
'fabric-ca-client'
);
const
{
FileSystemWallet
,
X509WalletMixin
}
=
require
(
'fabric-network'
);
const
fs
=
require
(
'fs'
);
const
path
=
require
(
'path'
);
const
ccpPath
=
path
.
resolve
(
__dirname
,
'.'
,
'network_profile.json'
);
const
ccpJSON
=
fs
.
readFileSync
(
ccpPath
,
'utf8'
);
const
ccp
=
JSON
.
parse
(
ccpJSON
);
const
admin_username
=
"ca-admin-orgca"
;
const
admin_password
=
"orgcapw"
;
const
ORGANISATION_MSP
=
"hlfMSP"
;
const
CA_ORGANISATION_NAME
=
"orgca"
;
async
function
main
()
{
try
{
// Create a new CA client for interacting with the CA.
const
caInfo
=
ccp
.
certificateAuthorities
[
CA_ORGANISATION_NAME
];
console
.
log
(
caInfo
);
const
caTLSCACerts
=
[];
//const caTLSCACerts = caInfo.tlsCACerts.pem;
const
ca
=
new
FabricCAServices
(
caInfo
.
url
,
{
trustedRoots
:
caTLSCACerts
,
verify
:
false
},
caInfo
.
caName
);
// 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:
${
walletPath
}
`
);
// Check to see if we've already enrolled the admin user.
const
adminExists
=
await
wallet
.
exists
(
'admin'
);
if
(
adminExists
)
{
console
.
log
(
'An identity for the admin user "admin" already exists in the wallet'
);
return
;
}
// Enroll the admin user, and import the new identity into the wallet.
const
enrollment
=
await
ca
.
enroll
({
enrollmentID
:
admin_username
,
enrollmentSecret
:
admin_password
});
const
identity
=
X509WalletMixin
.
createIdentity
(
ORGANISATION_MSP
,
enrollment
.
certificate
,
enrollment
.
key
.
toBytes
());
await
wallet
.
import
(
'admin'
,
identity
);
console
.
log
(
'Successfully enrolled admin user "admin" and imported it into the wallet'
);
}
catch
(
error
)
{
console
.
error
(
`Failed to enroll admin user "admin":
${
error
}
`
);
process
.
exit
(
1
);
}
}
main
();
fabric_node_sdk_tester/get_tls_certificates.sh
0 → 100644
View file @
433569b7
#!/bin/bash
set
-x
#echo on
IP_ADDRESS
=
"164.90.214.237"
REMOTE_MACHINE_TLS_CERT_FILE
=
"/root/hlft-store/hlfMSP/tlscacerts/tls-tlsca-7054.pem"
LOCAL_TLS_CERT_FILE
=
"./hlft-store/hlfMSP/tlscacerts/tls-tlsca-7054.pem"
scp
-r
root@
$IP_ADDRESS
:
$REMOTE_MACHINE_TLS_CERT_FILE
$LOCAL_TLS_CERT_FILE
\ No newline at end of file
fabric_node_sdk_tester/hlft-store/hlfMSP/tlscacerts/tls-tlsca-7054.pem
0 → 100644
View file @
433569b7
-----BEGIN CERTIFICATE-----
MIICATCCAaegAwIBAgIUP/fI4qZbd8HE2ZTS4OHbB9ntc7gwCgYIKoZIzj0EAwIw
XTELMAkGA1UEBhMCVVMxFzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMRQwEgYDVQQK
EwtIeXBlcmxlZGdlcjEPMA0GA1UECxMGRmFicmljMQ4wDAYDVQQDEwV0bHNjYTAe
Fw0yMDA4MTMwODU4MDBaFw0zNTA4MTAwODU4MDBaMF0xCzAJBgNVBAYTAlVTMRcw
FQYDVQQIEw5Ob3J0aCBDYXJvbGluYTEUMBIGA1UEChMLSHlwZXJsZWRnZXIxDzAN
BgNVBAsTBkZhYnJpYzEOMAwGA1UEAxMFdGxzY2EwWTATBgcqhkjOPQIBBggqhkjO
PQMBBwNCAASXGzTNSh2D/Fi2NaLTsygpLQshZppkQO9Wrq2km9VC5XFNUeaAtUSx
hGepwgKuQ1ofcZVLBRh3IZ3So9MDfftko0UwQzAOBgNVHQ8BAf8EBAMCAQYwEgYD
VR0TAQH/BAgwBgEB/wIBATAdBgNVHQ4EFgQUu7SghRZCw0VDPRR0CdUKoyfsMMkw
CgYIKoZIzj0EAwIDSAAwRQIhAOlDaWS4YC7GN9UVqW5WJR4mOcHAaeXEmsXDM1yN
CRUYAiAM+yZwJe11TbLSsmA0IaCN4tqU7DC4skR86CMcwhcT9A==
-----END CERTIFICATE-----
fabric_node_sdk_tester/hlft-store/orderer/tls-msp/tlscacerts/tls-tlsca-7054.pem
0 → 100644
View file @
433569b7
-----BEGIN CERTIFICATE-----
MIICADCCAaegAwIBAgIUaWBQK+8YCdldiOXOAc/1O/mR4UUwCgYIKoZIzj0EAwIw
XTELMAkGA1UEBhMCVVMxFzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMRQwEgYDVQQK
EwtIeXBlcmxlZGdlcjEPMA0GA1UECxMGRmFicmljMQ4wDAYDVQQDEwV0bHNjYTAe
Fw0yMDAxMDgxNTAwMDBaFw0zNTAxMDQxNTAwMDBaMF0xCzAJBgNVBAYTAlVTMRcw
FQYDVQQIEw5Ob3J0aCBDYXJvbGluYTEUMBIGA1UEChMLSHlwZXJsZWRnZXIxDzAN
BgNVBAsTBkZhYnJpYzEOMAwGA1UEAxMFdGxzY2EwWTATBgcqhkjOPQIBBggqhkjO
PQMBBwNCAAS5otE4Ab+ZDwQFJo2r6/B9XxX9ov++WEANsqR3+00xqEWGMCCIy4qm
7NRq5mVlLyZwN/gIKi3QB78hYln5KxqMo0UwQzAOBgNVHQ8BAf8EBAMCAQYwEgYD
VR0TAQH/BAgwBgEB/wIBATAdBgNVHQ4EFgQUWDuGHUYguQE2PFFzBRn4Xy4qgm4w
CgYIKoZIzj0EAwIDRwAwRAIgXLkp85Fxrr+yKJ2Ger4h+EDH/C617+it7+65ZaVh
GxQCIHAekGPEy91asdd7tnp+5De+IPzL0BVpgp4W9Y+KX+5E
-----END CERTIFICATE-----
fabric_node_sdk_tester/hlft-store/peer2/tls-msp/tlscacerts/tls-tlsca-7054.pem
0 → 100644
View file @
433569b7
-----BEGIN CERTIFICATE-----
MIICADCCAaegAwIBAgIUaWBQK+8YCdldiOXOAc/1O/mR4UUwCgYIKoZIzj0EAwIw
XTELMAkGA1UEBhMCVVMxFzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMRQwEgYDVQQK
EwtIeXBlcmxlZGdlcjEPMA0GA1UECxMGRmFicmljMQ4wDAYDVQQDEwV0bHNjYTAe
Fw0yMDAxMDgxNTAwMDBaFw0zNTAxMDQxNTAwMDBaMF0xCzAJBgNVBAYTAlVTMRcw
FQYDVQQIEw5Ob3J0aCBDYXJvbGluYTEUMBIGA1UEChMLSHlwZXJsZWRnZXIxDzAN
BgNVBAsTBkZhYnJpYzEOMAwGA1UEAxMFdGxzY2EwWTATBgcqhkjOPQIBBggqhkjO
PQMBBwNCAAS5otE4Ab+ZDwQFJo2r6/B9XxX9ov++WEANsqR3+00xqEWGMCCIy4qm
7NRq5mVlLyZwN/gIKi3QB78hYln5KxqMo0UwQzAOBgNVHQ8BAf8EBAMCAQYwEgYD
VR0TAQH/BAgwBgEB/wIBATAdBgNVHQ4EFgQUWDuGHUYguQE2PFFzBRn4Xy4qgm4w
CgYIKoZIzj0EAwIDRwAwRAIgXLkp85Fxrr+yKJ2Ger4h+EDH/C617+it7+65ZaVh
GxQCIHAekGPEy91asdd7tnp+5De+IPzL0BVpgp4W9Y+KX+5E
-----END CERTIFICATE-----
fabric_node_sdk_tester/invoke.js
0 → 100644
View file @
433569b7
/*
* SPDX-License-Identifier: Apache-2.0
*/
'use strict'
;
const
{
FileSystemWallet
,
Gateway
}
=
require
(
'fabric-network'
);
const
path
=
require
(
'path'
);
const
ccpPath
=
path
.
resolve
(
__dirname
,
'.'
,
'network_profile.json'
);
const
user_name
=
"lion"
;
const
CHANNEL_NAME
=
"appchannel"
;
const
CHAIN_CODE_NAME
=
"carcc"
;
const
CHAIN_CODE_FUNCTION_NAME
=
"createCar"
;
// const user_name = "lion";
// const CHANNEL_NAME = "appchannel";
// const CHAIN_CODE_NAME = "testcc";
// const CHAIN_CODE_FUNCTION_NAME = "invoke";
async
function
main
()
{
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:
${
walletPath
}
`
);
// Check to see if we've already enrolled the user.
const
userExists
=
await
wallet
.
exists
(
user_name
);
if
(
!
userExists
)
{
console
.
log
(
'An identity for the user "user1" 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
:
user_name
,
discovery
:
{
enabled
:
false
,
asLocalhost
:
false
}
});
// Get the network (channel) our contract is deployed to.
const
network
=
await
gateway
.
getNetwork
(
CHANNEL_NAME
);
// Get the contract from the network.
const
contract
=
network
.
getContract
(
CHAIN_CODE_NAME
);
// Submit the specified transaction.
// createCar transaction - requires 5 argument, ex: ('createCar', 'CAR12', 'Honda', 'Accord', 'Black', 'Tom')
// changeCarOwner transaction - requires 2 args , ex: ('changeCarOwner', 'CAR10', 'Dave')
await
contract
.
submitTransaction
(
CHAIN_CODE_FUNCTION_NAME
,
"BE8800"
,
"Opel"
,
"Corsa"
,
"Light Blue"
,
"7"
,
"2050"
,
"1"
);
//await contract.submitTransaction(CHAIN_CODE_FUNCTION_NAME, "b","a","1");
console
.
log
(
'Transaction has been submitted'
);
// Disconnect from the gateway.
await
gateway
.
disconnect
();
}
catch
(
error
)
{
console
.
error
(
`Failed to submit transaction:
${
error
}
`
);
process
.
exit
(
1
);
}
}
main
();
fabric_node_sdk_tester/network_profile.json
0 → 100644
View file @
433569b7
{
"name"
:
"hlf-bityoga"
,
"version"
:
"1.0.0"
,
"client"
:
{
"organization"
:
"hlf"
,
"connection"
:
{
"timeout"
:
{
"peer"
:
{
"endorser"
:
"300"
}
}
}
},
"channels"
:
{
"appchannel"
:
{
"orderers"
:
[
"orderer"
],
"peers"
:
{
"peer2"
:
{
"endorsingPeer"
:
"true"
,
"chaincodeQuery"
:
"true"
,
"ledgerQuery"
:
"true"
,
"eventSource"
:
"true"
,
"discover"
:
"true"
},
"peer1"
:
{
"endorsingPeer"
:
"false"
,
"chaincodeQuery"
:
"false"
,
"ledgerQuery"
:
"true"
,
"eventSource"
:
"false"
,
"discover"
:
"true"
}
}
}
},
"organizations"
:
{
"hlf"
:
{
"mspid"
:
"hlfMSP"
,
"peers"
:
[
"peer2"
,
"peer1"
],
"certificateAuthorities"
:
[
"orgca"
,
"tlsca"
]
}
},
"orderers"
:
{
"orderer"
:
{
"url"
:
"grpcs://164.90.214.237:8053"
,
"tlsCACerts"
:
{
"path"
:
"./hlft-store/hlfMSP/tlscacerts/tls-tlsca-7054.pem"
},
"grpcOptions"
:
{
"ssl-target-name-override"
:
"orderer"
}
}
},
"peers"
:
{
"peer2"
:
{
"url"
:
"grpcs://164.90.214.237:8055"
,
"tlsCACerts"
:
{
"path"
:
"./hlft-store/hlfMSP/tlscacerts/tls-tlsca-7054.pem"
},
"grpcOptions"
:
{
"ssl-target-name-override"
:
"peer2"
}
}
},
"certificateAuthorities"
:
{
"orgca"
:
{
"caName"
:
"orgca"
,
"url"
:
"https://164.90.214.237:8052"
,
"httpOptions"
:
{
"verify"
:
false
}
},
"tlsca"
:
{
"caName"
:
"tlsca"
,
"url"
:
"https://164.90.214.237:8081"
,
"httpOptions"
:
{
"verify"
:
false
}
}
}
}
fabric_node_sdk_tester/package.json
0 → 100644
View file @
433569b7
{
"engines"
:
{
"node"
:
">=8"
,
"npm"
:
">=5"
},
"scripts"
:
{
"lint"
:
"eslint ."
,
"pretest"
:
"npm run lint"
,
"test"
:
"nyc mocha --recursive"
},
"engineStrict"
:
true
,
"author"
:
"Hyperledger"
,
"license"
:
"Apache-2.0"
,
"dependencies"
:
{
"fabric-ca-client"
:
"~1.4.3"
,
"fabric-network"
:
"~1.4.3"
},
"devDependencies"
:
{
"chai"
:
"^4.2.0"
,
"eslint"
:
"^5.9.0"
,
"mocha"
:
"^5.2.0"
,
"nyc"
:
"^15.0.0"
,
"sinon"
:
"^7.1.1"
,
"sinon-chai"
:
"^3.3.0"
},
"nyc"
:
{
"exclude"
:
[
"coverage/**"
,
"test/**"
],
"reporter"
:
[
"text-summary"
,
"html"
],
"all"
:
true
,
"check-coverage"
:
true
,
"statements"
:
100
,
"branches"
:
100
,
"functions"
:
100
,
"lines"
:
100
}
}
fabric_node_sdk_tester/query.js
0 → 100644
View file @
433569b7
/*
* SPDX-License-Identifier: Apache-2.0
*/
'use strict'
;
const
{
FileSystemWallet
,
Gateway
}
=
require
(
'fabric-network'
);
const
path
=
require
(
'path'
);
const
ccpPath
=
path
.
resolve
(
__dirname
,
'.'
,
'network_profile.json'
);
const
user_name
=
"lion"
;
const
CHANNEL_NAME
=
"appchannel"
;
const
CHAIN_CODE_NAME
=
"carcc"
;
const
CHAIN_CODE_FUNCTION_NAME
=
"listCars"
;
// const user_name = "lion";
// const CHANNEL_NAME = "appchannel";
// const CHAIN_CODE_NAME = "testcc";
// const CHAIN_CODE_FUNCTION_NAME = "query";
async
function
main
()
{
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:
${
walletPath
}
`
);
// Check to see if we've already enrolled the user.
const
userExists
=
await
wallet
.
exists
(
user_name
);
if
(
!
userExists
)
{
console
.
log
(
'An identity for the user "user1" 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
:
user_name
,
discovery
:
{
enabled
:
false
,
asLocalhost
:
false
}
});
// Get the network (channel) our contract is deployed to.
const
network
=
await
gateway
.
getNetwork
(
CHANNEL_NAME
);
// Get the contract from the network.
const
contract
=
network
.
getContract
(
CHAIN_CODE_NAME
);
// Evaluate the specified transaction.
// queryCar transaction - requires 1 argument, ex: ('queryCar', 'CAR4')
// queryAllCars transaction - requires no arguments, ex: ('queryAllCars')
const
result
=
await
contract
.
evaluateTransaction
(
CHAIN_CODE_FUNCTION_NAME
);
//const result = await contract.evaluateTransaction(CHAIN_CODE_FUNCTION_NAME,"b");
//const result = await contract.evaluateTransaction(CHAIN_CODE_FUNCTION_NAME,"a");
console
.
log
(
`Transaction has been evaluated, result is:
${
result
.
toString
()}
`
);
process
.
exit
(
1
);
}
catch
(
error
)
{
console
.
error
(
`Failed to evaluate transaction:
${
error
}
`
);
//process.exit(1);
}
}
main
();
fabric_node_sdk_tester/registerUser.js
0 → 100644
View file @
433569b7
/*
* SPDX-License-Identifier: Apache-2.0
*/
'use strict'
;
const
{
FileSystemWallet
,
Gateway
,
X509WalletMixin
}
=
require
(
'fabric-network'
);
const
path
=
require
(
'path'
);
const
ccpPath
=
path
.
resolve
(
__dirname
,
'.'
,
'network_profile.json'
);
const
user_name
=
"lion"
;
const
user_password
=
"lion"
;
const
user_role
=
"client"
;
async
function
main
()
{
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:
${
walletPath
}
`
);
// Check to see if we've already enrolled the user.
const
userExists
=
await
wallet
.
exists
(
user_name
);
if
(
userExists
)
{
console
.
log
(
'An identity for the user "'
+
user_name
+
'" already exists in the wallet'
);
return
;
}
// Check to see if we've already enrolled the admin user.
const
adminExists
=
await
wallet
.
exists
(
'admin'
);
if
(
!
adminExists
)
{
console
.
log
(
'An identity for the admin user "admin" does not exist in the wallet'
);
console
.
log
(
'Run the enrollAdmin.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
:
'admin'
,
discovery
:
{
enabled
:
true
,
asLocalhost
:
false
}
});
// Get the CA client object from the gateway for interacting with the CA.
const
ca
=
gateway
.
getClient
().
getCertificateAuthority
();
const
adminIdentity
=
gateway
.
getCurrentIdentity
();
// Register the user, enroll the user, and import the new identity into the wallet.
const
secret
=
await
ca
.
register
({
enrollmentID
:
user_name
,
role
:
user_role
,
enrollmentSecret
:
user_password
},
adminIdentity
);
const
enrollment
=
await
ca
.
enroll
({
enrollmentID
:
user_name
,
enrollmentSecret
:
secret
});
const
userIdentity
=
X509WalletMixin
.
createIdentity
(
'hlfMSP'
,
enrollment
.
certificate
,
enrollment
.
key
.
toBytes
());
await
wallet
.
import
(
user_name
,
userIdentity
);
console
.
log
(
'Successfully registered and enrolled user "'
+
user_name
+
'" with role "'
+
user_role
+
'" and imported it into the wallet'
);
}
catch
(
error
)
{
console
.
error
(
`Failed to register user "user_name":
${
error
}
`
);
process
.
exit
(
1
);
}
}
main
();
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