wighawag / hardhat-deploy

hardhat deployment plugin
MIT License
1.17k stars 283 forks source link

Support Custom Signer #482

Open AlissonRS opened 10 months ago

AlissonRS commented 10 months ago

I'd love to have an option to provide a custom signer, which internally can do any logic I want for signing transactions.

Maybe I want to require multi-signature, use a DefenderRelaySigner (I think this was being discussed here #101 ) or just send the raw transaction to my private backend that will do offline signature in a closed environment, or a combination of them.

I'm keen on implementing this myself and contributing to the project as this is a great library.

Hardhat-deploy could expose an interface for signing like this (so it's not tied to ethers.js/web3.js or any other libraries):

interface IHardhatSigner {
    sign(rawTransaction: string): Promise<string>;
}

I could have my own implementation:

class MyRemoteSigner implements IHardhatSigner {
  async sign(message: string): Promise<string> {
    // Use a backend signer or whatever logic I want
  }
}

Then provide to network config:

hardhat.config.ts

    eth: {
      signer: new MyRemoteSigner(),
      chainId: chainIds["eth"],
      url: `https://eth.public-rpc.com`
    },

Could also be provided as an optional field to the deploy() function.