-
Notifications
You must be signed in to change notification settings - Fork 307
feat: add fetchEncryptedPrivKeys.ts #2080
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /** | ||
| * This tool will help you creates a private key JSON file to be used with the external singing mode feature. | ||
| * It creates a JSON file containing a list of wallet IDs and their corresponding encrypted user private keys. | ||
| * | ||
| * To run this file, use the command: | ||
| * `yarn ts-node <path/to/fetchEncryptedPrivKeys.ts>` | ||
| * | ||
| * Copyright 2022, BitGo, Inc. All Rights Reserved. | ||
| */ | ||
| import { writeFile } from 'fs'; | ||
| import { BitGo } from 'bitgo'; | ||
|
|
||
| type Output = { | ||
| [key: string]: string | ||
| } | ||
|
|
||
| type WalletIds = { | ||
| [key: string]: string[] | ||
| } | ||
|
|
||
| // TODO: set env to 'test' or 'prod' | ||
|
tylerlevine marked this conversation as resolved.
Outdated
|
||
| const bg = new BitGo({ env: 'test' }); | ||
| // TODO: set your access token here | ||
| const accessToken = ''; | ||
| // // TODO: set your coin type and wallet ids here e.g. | ||
| const walletIds: WalletIds = { | ||
| // tbtc: ['61f039aad587c2000745c687373e0111', '6225b081cd291300071fed36b1362222'], | ||
| // gteth: ['61fb21819c54dd000755f8de3a18e333'], | ||
| }; | ||
|
|
||
| async function main() { | ||
| bg.authenticateWithAccessToken({ accessToken }); | ||
|
|
||
| // get the encrypted user privKey for each walletId and store in the JSON output | ||
| const output: Output = {}; | ||
| for (const [coinName, ids] of Object.entries(walletIds)) { | ||
| const coin = bg.coin(coinName); | ||
| for (const id of ids) { | ||
| const wallet = await coin.wallets().get({ id }); | ||
| const userKeyId = wallet.keyIds()[0]; | ||
| const keychain = await coin.keychains().get({ id: userKeyId }); | ||
| if (keychain.encryptedPrv === undefined) { | ||
| console.warn(`could not find a ${coinName} encrypted user private key for wallet id ${id}, skipping`); | ||
| continue; | ||
| } | ||
| output[id] = keychain.encryptedPrv; | ||
| } | ||
| } | ||
|
|
||
| const data = JSON.stringify(output, null, '\t'); | ||
| const fileName = 'encryptedPrivKeys.json'; | ||
| writeFile(fileName, data, (err) => { | ||
| if (err) { | ||
| throw err; | ||
| } | ||
| console.log(`Wallet IDs and encrypted private keys saved to ${fileName}`); | ||
| }); | ||
| } | ||
|
|
||
| main().catch((e) => console.error(e)); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.