I am trying to integrate KMS (Amazon) with ethers for signing the typedData and verify the signer in the smart contract.
Before :
The private key was saved as environment variable. Since it could be a security issue and potentially lose funds locked in it. Also the signer is the owner of the smart contract.
Present :
Instead of signing the msg with the private key stored in the server, i want to sign the data using the private key stored in KMS. I have integrated KMS before for signing a transaction and sending, however i am unsure how to go about for the typed data.
Code snippet - Original one with ethers
const { ethers } = require("ethers");
let privateKey = "";
let signer = new ethers.Wallet(privateKey);
let signature = await signer._signTypedData( {
name: "name",
version: "1.0.0",
chainId: 4,
verifyingContract: ""
},
{
Request: [
{
name: "id",
type: "string",
},
{
name: "amount",
type: "uint256",
},
{
name: "wallet",
type: "address",
},
],
},
{
id: "id",
amount: 1,
wallet: ""
});
OUTPUT :
Signature sample output :
0x8dea897d8a25b32a354d41c1c6d96aa6c19466a8a743fc41c3c3da97d7cd9fb131f0e905b96c4bfb560a74fb52ae454ca1a73b7189710fc6a35236d0bc11d1d51c
Here's what i have tried so far:
Tried to convert the typed data to a signable message using eip-712 npm package and then trying to sign it with KMS. However , the signature did not get verified.
ethers-aws-kms-signer
Tried to send a transaction using the above package , even sendTransaction is throwing error
"KeyId missing in the params"
- Tried to implement the concept used in celo-monorepo. That did not work out for me. Reference
- Then it was bunch of hit and trials.
Can anyone give me an idea on how to achieve this ? I cannot change the JSON schema for the typed data since the contract is already deployed.
Appreciate your time. Please comment.
Thanks!