|
1 | | -# ethers-gcp-kms-signer |
| 1 | +# ethers-gcp-kms-signer |
| 2 | + |
| 3 | +This is a wallet or signer that can be used together with [Ethers.js](https://github.com/ethers-io/ethers.js/) applications. |
| 4 | + |
| 5 | +## Getting Started |
| 6 | + |
| 7 | +```sh |
| 8 | +npm i ethers-gcp-kms-signer |
| 9 | +``` |
| 10 | + |
| 11 | +1. Create your asymmetric key as follows: https://cloud.google.com/kms/docs/creating-asymmetric-keys |
| 12 | + |
| 13 | +2. Add the new service account to GCP with the correct KMS roles: Crypto KMS `Signer`, `Verifier`, `Viewer` |
| 14 | + |
| 15 | +3. Provide the GCP service account credentials using an environment variable called `GOOGLE_APPLICATION_CREDENTIALS` [here](https://cloud.google.com/kms/docs/accessing-the-api#non_google_production_environment) |
| 16 | + |
| 17 | +4. Use the `GcpKmsSigner` constructor as shown below, and that will resolve the correct key to sign the transaction. |
| 18 | + |
| 19 | +```js |
| 20 | +import { GcpKmsSigner } from "ethers-gcp-kms-signer"; |
| 21 | + |
| 22 | +const kmsCredentials = { |
| 23 | + projectId: "gcp-project-id", // your project id in gcp |
| 24 | + locationId: "global", // the location where your key ring was created |
| 25 | + keyRingId: "kr-1", // the id of the key ring |
| 26 | + keyId: "key-name", // the name/id of your key in the key ring |
| 27 | + keyVersion: "1", // the version of the key |
| 28 | +}; |
| 29 | + |
| 30 | +const provider = ethers.providers.getDefaultProvider("ropsten"); |
| 31 | +let signer = new GcpKmsSigner(kmsCredentials); |
| 32 | +signer = signer.connect(provider); |
| 33 | + |
| 34 | +const tx = await signer.sendTransaction({ |
| 35 | + to: "0xE94E130546485b928C9C9b9A5e69EB787172952e", |
| 36 | + value: ethers.utils.parseEther("0.01"), |
| 37 | +}); |
| 38 | +console.log(tx); |
| 39 | +``` |
| 40 | + |
| 41 | +# Developers |
| 42 | + |
| 43 | +## Install |
| 44 | + |
| 45 | +`git clone` this repo |
| 46 | + |
| 47 | +```sh |
| 48 | +$ git clone https://github.com/openlawteam/ethers-gcp-kms-signer my-module |
| 49 | +$ cd my-module |
| 50 | +$ rm -rf .git |
| 51 | +$ npm install # or yarn |
| 52 | +``` |
| 53 | + |
| 54 | +Just make sure to edit `package.json`, `README.md` and `LICENSE` files accordingly with your module's info. |
| 55 | + |
| 56 | +## Commands |
| 57 | + |
| 58 | +```sh |
| 59 | +$ npm test # run tests with Jest |
| 60 | +$ npm run coverage # run tests with coverage |
| 61 | +$ npm run lint # lint code |
| 62 | +$ npm run build # generate docs and transpile code |
| 63 | +``` |
| 64 | + |
| 65 | +## Commit message format |
| 66 | + |
| 67 | +This boiler plate uses the **semantic-release** package to manage versioning. Once it has been set up, version numbers and Github release changelogs will be automatically managed. **semantic-release** uses the commit messages to determine the type of changes in the codebase. Following formalized conventions for commit messages, **semantic-release** automatically determines the next [semantic version](https://semver.org) number, generates a changelog and publishes the release. |
| 68 | + |
| 69 | +Use `npm run commit` instead of `git commit` in order to invoke Commitizen commit helper that helps with writing properly formatted commit messages. |
| 70 | + |
| 71 | +## License |
| 72 | + |
| 73 | +MIT |
| 74 | + |
| 75 | +# Credits |
| 76 | + |
| 77 | +All the credits to |
| 78 | + |
| 79 | +- [RJ Chow](https://github.com/rjchow) for integrating AWS KMS signer with Ethers.js and share that with everyone at https://github.com/rjchow/ethers-aws-kms-signer |
| 80 | + |
| 81 | +- Lucas Henning for doing the legwork on parsing the AWS KMS signature and public key asn formats: https://luhenning.medium.com/the-dark-side-of-the-elliptic-curve-signing-ethereum-transactions-with-aws-kms-in-javascript-83610d9a6f81 |
0 commit comments