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

Add support for eth private key #375

Merged
merged 3 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions .github/workflows/cd-dashboard-element-ropsten.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ env:
ETHEREUM_RPC_URL: ${{ secrets.ETHEREUM_RPC_URL }}
ETHEREUM_PROVIDER: ${{ secrets.ETHEREUM_PROVIDER }}
ETHEREUM_MNEMONIC: ${{ secrets.ETHEREUM_MNEMONIC }}
ETHEREUM_PRIVATE_KEY: ${{ secrets.ETHEREUM_PRIVATE_KEY }}

jobs:
deploy:
Expand Down Expand Up @@ -66,5 +67,6 @@ jobs:
--set-env-vars ETHEREUM_RPC_URL="${{ env.ETHEREUM_RPC_URL }}" \
--set-env-vars ETHEREUM_PROVIDER="${{ env.ETHEREUM_PROVIDER }}" \
--set-env-vars ETHEREUM_MNEMONIC="${{ env.ETHEREUM_MNEMONIC }}" \
--set-env-vars ETHEREUM_PRIVATE_KEY="${{ env.ETHEREUM_PRIVATE_KEY }}" \
--service-account "${{ env.GCP_RUNNER_SA }}" \
--quiet
3 changes: 2 additions & 1 deletion packages/dashboard/.env.ropsten.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ ELEMENT_CONTENT_ADDRESSABLE_STORE_SERVICE_URI=''
ELEMENT_ANCHOR_CONTRACT="0x920b7DEeD5CdE055260cdDBD70C000Bbd5b30997"
ETHEREUM_RPC_URL=''
ETHEREUM_PROVIDER=$ETHEREUM_RPC_URL
ETHEREUM_MNEMONIC="your mnemonic phrase here"
ETHEREUM_MNEMONIC="your mnemonic phrase here"
ETHEREUM_PRIVATE_KEY="your private key here (will be ignored if ETHEREUM_MNEMONIC is provided)"
2 changes: 2 additions & 0 deletions packages/dashboard/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const config: any = {
process.env.ELEMENT_CONTENT_ADDRESSABLE_STORE_SERVICE_URI,
ethereumRpcUrl: process.env.ETHEREUM_RPC_URL,
ethereumMnemonic: process.env.ETHEREUM_MNEMONIC,
ethereumPrivateKey: process.env.ETHEREUM_PRIVATE_KEY,
elementAnchorContract: process.env.ELEMENT_ANCHOR_CONTRACT,
awsCredentials: {
region: process.env.AWS_DEFAULT_REGION,
Expand Down Expand Up @@ -70,6 +71,7 @@ export const elementNodeConfigs = {
],
elementAnchorContract: config.elementAnchorContract,
ethereumMnemonic: config.ethereumMnemonic,
ethereumPrivateKey: config.ethereumPrivateKey,
};

export const photonNodeConfigs = {
Expand Down
1 change: 1 addition & 0 deletions packages/dashboard/docker-compose.run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ services:
- ETHEREUM_RPC_URL=${ETHEREUM_RPC_URL}
- ETHEREUM_PROVIDER=${ETHEREUM_PROVIDER}
- ETHEREUM_MNEMONIC=${ETHEREUM_MNEMONIC}
- ETHEREUM_PRIVATE_KEY=${ETHEREUM_PRIVATE_KEY}
- S3_BUCKET_NAME=${S3_BUCKET_NAME}
- QLDB_LEDGER=${QLDB_LEDGER}
- QLDB_LEDGER_TABLE=${QLDB_LEDGER_TABLE}
Expand Down
3 changes: 2 additions & 1 deletion packages/dashboard/docs/deploy-to-gcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ The following environment variables are needed to run the node, we set them for
- ETHEREUM_RPC_URL: URL to use to connect to ethereum network
- ETHEREUM_PROVIDER: Same as RPC URL
- ETHEREUM_MNEMONIC: The mnemonic to use to associate an ethereum account with for the transactions, see [Metamask term](https://docs.metamask.io/guide/common-terms.html#mnemonic-phrase-seed-phrase-seed-words) and [Metamask guide](https://metamask.zendesk.com/hc/en-us/articles/360015290032-How-to-reveal-your-Secret-Recovery-Phrase)
- ETHEREUM_PRIVATE_KEY: The private key associated with the funded Ethereum address (will be ignored if ETHEREUM_MNEMONIC is provided)

Other useful GCP CLI commands:

Expand Down Expand Up @@ -100,4 +101,4 @@ gcloud beta run domain-mappings create --service <service-name> --domain <custom
# Domain creation and mapping takes a while, this command can be used to check the status of the domain
gcloud beta run domain-mappings describe --domain <custom-domain>
```
Once the changes propagate you will be able to go to the custom domain.
Once the changes propagate you will be able to go to the custom domain.
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,9 @@ To use this service, you must edit the environment variable in the Sidetree.js
repository before starting the Sidetree-Element service. Specifically we want
to set `MONGO_DB_CONNECTION_STRING` and `ELEMENT_CONTENT_ADDRESSABLE_STORE_SERVICE_URI`
to use the services running on localhost. For `ETHEREUM_RPC_URL` we want to
provide our API url and key. And on `ETHEREUM_MNEMONIC` we will need to provide
the mnemonic phrase for a minimally funded wallet to use the service.
provide our API url and key. And on `ETHEREUM_MNEMONIC` / `ETHEREUM_PRIVATE_KEY` we
will need to provide the mnemonic phrase or private key for a minimally funded wallet
to use the service.

```
$ cd /home/ubuntu/sidetree.js/packages/dashboard
Expand All @@ -232,6 +233,7 @@ ELEMENT_ANCHOR_CONTRACT="0x920b7DEeD5CdE055260cdDBD70C000Bbd5b30997"
ETHEREUM_RPC_URL='https://ropsten.infura.io/v3/[YOUR_PROJECT_API_KEY]'
ETHEREUM_PROVIDER=$ETHEREUM_RPC_URL
ETHEREUM_MNEMONIC='[YOUR_MNEMONIC_PHRASE]'
ETHEREUM_PRIVATE_KEY='[YOUR_PRIVATE_KEY]'
--- End Contents
```

Expand Down
7 changes: 7 additions & 0 deletions packages/did-method-element/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type ElementNodeConfigs = {
];
elementAnchorContract?: string;
ethereumMnemonic?: string;
ethereumPrivateKey?: string;
};

const getLedger = async (elementNodeConfigs: ElementNodeConfigs) => {
Expand All @@ -34,6 +35,12 @@ const getLedger = async (elementNodeConfigs: ElementNodeConfigs) => {
providerOrUrl: elementNodeConfigs.ethereumRpcUrl,
});
web3 = new Web3(provider);
} else if (elementNodeConfigs.ethereumPrivateKey) {
const provider = new HDWalletProvider({
privateKeys: [elementNodeConfigs.ethereumPrivateKey],
providerOrUrl: elementNodeConfigs.ethereumRpcUrl,
});
web3 = new Web3(provider);
}
const ledger = new EthereumLedger(
web3,
Expand Down