Skip to content

Commit e290230

Browse files
committed
feat: gcp kms signer
1 parent 0ea082b commit e290230

18 files changed

+32156
-1
lines changed

.babelrc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"presets": [
3+
[
4+
"@babel/preset-env",
5+
{
6+
"targets": {
7+
"node": 6
8+
}
9+
}
10+
],
11+
"@babel/preset-typescript"
12+
],
13+
"plugins": [
14+
"@babel/plugin-proposal-class-properties",
15+
"@babel/plugin-proposal-optional-chaining",
16+
"@babel/plugin-proposal-nullish-coalescing-operator"
17+
]
18+
}

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
coverage
2+
dist
3+
node_modules

.eslintrc

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"parser": "babel-eslint",
3+
"extends": [
4+
"airbnb-base",
5+
"plugin:prettier/recommended"
6+
],
7+
"env": {
8+
"jest": true
9+
},
10+
"settings": {
11+
"import/resolver": {
12+
"node": {
13+
"extensions": [
14+
".js",
15+
".jsx",
16+
".ts",
17+
".tsx"
18+
]
19+
}
20+
}
21+
},
22+
"overrides": [
23+
{
24+
"files": [
25+
"**/*.ts",
26+
"**/*.tsx"
27+
],
28+
"parser": "@typescript-eslint/parser",
29+
"parserOptions": {
30+
"project": "./tsconfig.json"
31+
},
32+
"plugins": [
33+
"@typescript-eslint"
34+
],
35+
"rules": {
36+
"no-undef": "off",
37+
"no-unused-vars": "off",
38+
"no-restricted-globals": "off"
39+
}
40+
}
41+
],
42+
"rules": {
43+
"import/extensions": "off",
44+
"import/prefer-default-export": "off",
45+
"import/no-default-export": "error",
46+
"no-underscore-dangle": [
47+
2,
48+
{
49+
"allowAfterThis": true
50+
}
51+
]
52+
}
53+
}

.github/workflow/release.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Release
2+
on:
3+
push:
4+
branches:
5+
- main
6+
jobs:
7+
release:
8+
name: Release
9+
runs-on: ubuntu-latest
10+
environment:
11+
name: 'NPM Deploy'
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
with:
16+
fetch-depth: 0
17+
- name: Setup Node.js
18+
uses: actions/setup-node@v1
19+
with:
20+
node-version: 12
21+
- name: Install dependencies
22+
run: npm ci
23+
- name: Release
24+
env:
25+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
26+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
27+
run: npx semantic-release

.github/workflow/test.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: CI
2+
3+
on: [push]
4+
5+
jobs:
6+
test:
7+
name: Lint & Test
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- uses: actions/setup-node@v1
12+
with:
13+
node-version: 12.x
14+
- name: Cache Node Modules
15+
uses: actions/cache@v2
16+
env:
17+
cache-name: cache-node-modules
18+
with:
19+
# npm cache files are stored in `~/.npm` on Linux/macOS
20+
path: ~/.npm
21+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
22+
restore-keys: |
23+
${{ runner.os }}-build-${{ env.cache-name }}-
24+
${{ runner.os }}-build-
25+
${{ runner.os }}-
26+
- name: Install Packages
27+
# there's a problem with ganache-core using a very old version of ethereumjs-abi which fails on git checkout with ssh reasons
28+
run: |
29+
git config --global url."https://".insteadOf git://
30+
git config --global url."https://".insteadOf git+https://
31+
git config --global url."https://".insteadOf ssh://git
32+
npm ci
33+
- name: Check Lint
34+
run: npm run lint
35+
- name: Test
36+
run: npm run test
37+
- name: Build
38+
run: npm run build

.prettierrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"printWidth": 120
3+
}

.releaserc.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
branch: main
2+
extends: "semantic-release-npm-github-publish"

.yo-rc.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"generator-semantic-module": {
3+
"packager": "npm",
4+
"commitizen-adapter": "@commitlint/prompt",
5+
"commitlint-config": "@commitlint/config-conventional"
6+
}
7+
}

README.md

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,81 @@
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

commitlint.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* eslint-env node */
2+
3+
module.exports = {
4+
extends: ["@commitlint/config-conventional"],
5+
6+
// Add your own rules. See http://marionebl.github.io/commitlint
7+
rules: {},
8+
};

0 commit comments

Comments
 (0)