Skip to content

Commit 22f016d

Browse files
committed
contract details fetch from .env added
1 parent 5b92673 commit 22f016d

File tree

4 files changed

+45
-13
lines changed

4 files changed

+45
-13
lines changed

.env.example

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
FUNDING_ACCOUNT="**private key of the account used to fund the newly created accounts **"
2-
IBLOCK_WSURL="Ethereum project url of the blockchain to connect"
2+
IBLOCK_WSURL="Ethereum project url of the blockchain to connect"
3+
IBLOCK_VERIFIER_PRIVATE_KEY="**Private key of the Ethereum Account Address of the verifier**"
4+
IBLOCK_VERIFIER_ADDRESS="**Ethereum Account Address of the verifier**"
5+
IBLOCK_VERIFIER_CONTRACT_ADDRESS="**Smart Contract address of the verifier**"

Readme.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ Include the following variables in your `.env` file, or in the environment varia
2222

2323
Integrate the below explained functions to use the 'iBlock Person Verification Platform' in your web server.
2424

25-
If you are restoring the integration of 'iBlock Person Verification Platform', create a file name `deployed-contract` on your backend server with the details of your previously deployed smart contract. Refer `deployed-contract.example` file for the format.
25+
If you are restoring the integration of 'iBlock Person Verification Platform', add the following fields to your `.env` with the details of your already deployed smart contract addresses.
26+
27+
`IBLOCK_VERIFIER_PRIVATE_KEY`
28+
`IBLOCK_VERIFIER_ADDRESS`
29+
`IBLOCK_VERIFIER_CONTRACT_ADDRESS`
30+
31+
Refer `.env.example` file for the format.
2632
## Functions
2733

2834
<dl>

api.js

+33-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const qrgen = require("qrcode");
22
const fs = require("fs");
33
const crypto = require("crypto");
4+
require("dotenv").config();
45

56
const {
67
deployContract,
@@ -13,6 +14,13 @@ const {
1314
getUserGender,
1415
} = require("./contract");
1516

17+
/**
18+
* Check for the verifier contract address details in the .env
19+
* @returns {Bool}
20+
*/
21+
function isInConfigs() {
22+
return(process.env.IBLOCK_VERIFIER_PRIVATE_KEY && process.env.IBLOCK_VERIFIER_ADDRESS && process.env.IBLOCK_VERIFIER_CONTRACT_ADDRESS)
23+
}
1624
/**
1725
* Load ( or deploy and load) the smart contract tied to the verifier.
1826
*
@@ -31,6 +39,9 @@ const {
3139
*
3240
*/
3341
async function loadContract() {
42+
if (isInConfigs()) {
43+
return({"private-key": process.env.IBLOCK_VERIFIER_PRIVATE_KEY,"verifier-address": process.env.IBLOCK_VERIFIER_ADDRESS,"contract-address": process.env.IBLOCK_VERIFIER_CONTRACT_ADDRESS})
44+
}
3445
if (!fs.existsSync("./deployed-contract")) {
3546
return deployContract()
3647
.then((depObj) => {
@@ -70,11 +81,17 @@ async function loadContract() {
7081
*
7182
*/
7283
async function getQR(_verifierName) {
73-
const deployedContract = await JSON.parse(
74-
fs.readFileSync("./deployed-contract", {
75-
encoding: "utf8",
76-
})
77-
);
84+
let deployedContract;
85+
if (isInConfigs()) {
86+
deployedContract = {"private-key": process.env.IBLOCK_VERIFIER_PRIVATE_KEY,"verifier-address": process.env.IBLOCK_VERIFIER_ADDRESS,"contract-address": process.env.IBLOCK_VERIFIER_CONTRACT_ADDRESS}
87+
}
88+
else {
89+
deployedContract = await JSON.parse(
90+
fs.readFileSync("./deployed-contract", {
91+
encoding: "utf8",
92+
})
93+
);
94+
}
7895

7996
const token =
8097
new Date().toISOString() + crypto.randomBytes(22).toString("hex");
@@ -112,11 +129,17 @@ async function getQR(_verifierName) {
112129
*
113130
*/
114131
async function getTokenVerified(_token, _listOfDataFields) {
115-
const deployedContract = await JSON.parse(
116-
fs.readFileSync("./deployed-contract", {
117-
encoding: "utf8",
118-
})
119-
);
132+
let deployedContract;
133+
if (isInConfigs()) {
134+
deployedContract = {"private-key": process.env.IBLOCK_VERIFIER_PRIVATE_KEY,"verifier-address": process.env.IBLOCK_VERIFIER_ADDRESS,"contract-address": process.env.IBLOCK_VERIFIER_CONTRACT_ADDRESS}
135+
}
136+
else {
137+
deployedContract = await JSON.parse(
138+
fs.readFileSync("./deployed-contract", {
139+
encoding: "utf8",
140+
})
141+
);
142+
}
120143

121144
const response = await getVerifiedToken(
122145
_token,

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "iblock-verifier",
3-
"version": "1.0.2",
3+
"version": "1.1.0",
44
"description": "Integration Library for IdentityBlock Person Verification Platform",
55
"main": "api.js",
66
"scripts": {

0 commit comments

Comments
 (0)