Skip to content

Commit bfc4875

Browse files
using farmer ethaddress as _id
1 parent a74ee32 commit bfc4875

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

backend/src/routes/farmer-route.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import { kmsAuth } from "../integrations/Blockchain/web3/authentication-function
99

1010
const EISKey = process.env.EIS_apiKey;
1111

12+
//Authenticate with AWS KMS
13+
const kms = kmsAuth();
14+
1215
if (EISKey == undefined) {
1316
console.error("You must define 'EIS_apiKey' in the environment!");
1417
process.exit(-1);
@@ -112,10 +115,7 @@ export interface FarmerAddDTO {
112115
}
113116

114117
// Create Pub/Priv key on AWS KMS using the FarmerId as alias
115-
const createEthAccount = async(farmerId: String) => {
116-
117-
//Authenticate
118-
const kms = kmsAuth();
118+
const createEthAccount = async(farmerId: String) => {
119119

120120
//Create Key
121121
const cmk = await kms.createKey({
@@ -164,6 +164,11 @@ router.post("/add", async(req: Request, res: Response) => {
164164
//Create and set ethAccount keyID to the farmer object
165165
const farmerKeyId = await createEthAccount(field.farmer_id);
166166
farmerDoc.ethKeyID = farmerKeyId;
167+
168+
// Set FarmerId to ETH Address
169+
const farmerPubKey = kms.getPublicKey(farmerKeyId);
170+
const ethAddress = kms.getEthereumAddress(farmerPubKey);
171+
farmerDoc._id = ethAddress;
167172
await farmerDoc.save();
168173

169174

0 commit comments

Comments
 (0)