Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using farmer ethaddress as _id #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions backend/src/routes/farmer-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { kmsAuth } from "../integrations/Blockchain/web3/authentication-function

const EISKey = process.env.EIS_apiKey;

//Authenticate with AWS KMS
const kms = kmsAuth();

if (EISKey == undefined) {
console.error("You must define 'EIS_apiKey' in the environment!");
process.exit(-1);
Expand Down Expand Up @@ -112,10 +115,7 @@ export interface FarmerAddDTO {
}

// Create Pub/Priv key on AWS KMS using the FarmerId as alias
const createEthAccount = async(farmerId: String) => {

//Authenticate
const kms = kmsAuth();
const createEthAccount = async(farmerId: String) => {

//Create Key
const cmk = await kms.createKey({
Expand Down Expand Up @@ -164,6 +164,11 @@ router.post("/add", async(req: Request, res: Response) => {
//Create and set ethAccount keyID to the farmer object
const farmerKeyId = await createEthAccount(field.farmer_id);
farmerDoc.ethKeyID = farmerKeyId;

// Set FarmerId to ETH Address
const farmerPubKey = kms.getPublicKey(farmerKeyId);
const ethAddress = kms.getEthereumAddress(farmerPubKey);
farmerDoc._id = ethAddress;
await farmerDoc.save();


Expand Down