From 8c0f56914262781981686e9a028cf684c50da152 Mon Sep 17 00:00:00 2001 From: Alejandro Busse Date: Mon, 10 Jul 2023 12:22:01 -0300 Subject: [PATCH] feat(express): improve fetchEncryptedPrivKeys script improve fetchEncryptedPrivKeys script WP-186 --- modules/express/EXTERNAL_SIGNER.md | 18 +++++++++++++----- modules/express/src/fetchEncryptedPrivKeys.ts | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/modules/express/EXTERNAL_SIGNER.md b/modules/express/EXTERNAL_SIGNER.md index 0cc291ffde..4a8bdc41f2 100644 --- a/modules/express/EXTERNAL_SIGNER.md +++ b/modules/express/EXTERNAL_SIGNER.md @@ -30,11 +30,13 @@ The file is located at `src/fetchEncryptedPrivKeys.ts`. Before using this tool, 1. Fill in the `TODOs` by providing a valid `accessToken` as well as the list of `walletIds`, grouped by the cryptocurrency. 2. Using the same information as #1, update the .env file with the `accessToken` and `walletIds` information. -| Name | Value | Description | -| ---------------------------------- | ------ | ---------------------------------------------- | -| BITGO_EXTERNAL_SIGNER_ENV | string | test | -| BITGO_EXTERNAL_SIGNER_ACCESS_TOKEN | string | Access token used for access BitGo Wallets | -| BITGO_EXTERNAL_SIGNER_WALLET_IDS | string | JSON formatted string of wallets and their ids | +| Name | Value | Description | +| ----------------------------------------- | ------ | ---------------------------------------------- | +| BITGO_EXTERNAL_SIGNER_ENV | string | test | +| BITGO_EXTERNAL_SIGNER_ACCESS_TOKEN | string | Access token used for access BitGo Wallets | +| BITGO_EXTERNAL_SIGNER_WALLET_IDS | string | JSON formatted string of wallets and their ids | +| BITGO_EXTERNAL_SIGNER_WALLET_IDS_WITH_PRV | string | JSON formatted string of wallets ids and | +| | | their encrypted private keys | BITGO_EXTERNAL_SIGNER_WALLET_IDS examples: @@ -43,6 +45,12 @@ BITGO_EXTERNAL_SIGNER_WALLET_IDS={"tbtc":["xxx", "xxx"], "gteth": ["xxx"]} BITGO_EXTERNAL_SIGNER_WALLET_IDS={"tbtc":[{"walletId":"xxx","walletPassword":"xxx","secret":"xxx"}]} ``` +BITGO_EXTERNAL_SIGNER_WALLET_IDS_WITH_PRV examples: + +``` +BITGO_EXTERNAL_SIGNER_WALLET_IDS_WITH_PRV=[{"walletId":"xxx","encryptedPrv":"xxx"}] +``` + Option #2 may make be more convenient for configuration instead of reconfiguring the file every time a new version is released both locally and to Docker. An example is provided in the file. To run the file, use the command: diff --git a/modules/express/src/fetchEncryptedPrivKeys.ts b/modules/express/src/fetchEncryptedPrivKeys.ts index 2aa51a6223..2e3ed91bf9 100644 --- a/modules/express/src/fetchEncryptedPrivKeys.ts +++ b/modules/express/src/fetchEncryptedPrivKeys.ts @@ -25,8 +25,14 @@ type WalletIds = { [key: string]: (string | Credentials)[]; }; +type WalletWithPrv = Array<{ + walletId: string; + encryptedPrv: string; +}>; + const esAccessToken = process.env.BITGO_EXTERNAL_SIGNER_ACCESS_TOKEN; const esWalletIDs = process.env.BITGO_EXTERNAL_SIGNER_WALLET_IDS; // example: {"tbtc":[{"walletId":"xxx","walletPassword":"xxx","secret":"xxx"}]} +const esWalletWithPrv = process.env.BITGO_EXTERNAL_SIGNER_WALLET_IDS_WITH_PRV; // example: [{"walletId":"xxx","encryptedPrv":"xxx"}] // TODO: set env to 'test' or 'prod' const bg = new BitGo({ env: (process.env.BITGO_EXTERNAL_SIGNER_ENV as EnvironmentName) ?? 'test' }); @@ -46,6 +52,15 @@ const walletIds: WalletIds = esWalletIDs ? JSON.parse(esWalletIDs) : {}; // gteth: ['61fb21819c54dd000755f8de3a18e333'], // }; +// TODO: set walletId and encryptedPrv here e.g. +const walletWithPrv: WalletWithPrv = esWalletWithPrv ? JSON.parse(esWalletWithPrv) : []; +// [ +// { +// walletId: '', +// encryptedPrv: '', +// }, +// ]; + export async function fetchKeys(ids: WalletIds, token: string, accessToken?: string): Promise> { bg.authenticateWithAccessToken({ accessToken: token }); @@ -73,6 +88,10 @@ export async function fetchKeys(ids: WalletIds, token: string, accessToken?: str } } + for (const { walletId, encryptedPrv } of walletWithPrv) { + output[walletId] = encryptedPrv; + } + const data = JSON.stringify(output, null, '\t'); const fileName = 'encryptedPrivKeys.json'; writeFile(fileName, data, (err) => {