-
Notifications
You must be signed in to change notification settings - Fork 300
docs(examples): add wallet passphrase recovery example script #7285
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
+88
−0
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,88 @@ | ||
| #!/usr/bin/env node | ||
| /** | ||
| * Wallet Passphrase Recovery Script | ||
| * | ||
| * This script takes box D information in the keycard and recovers the wallet passphrase. | ||
| * | ||
| * The script will prompt for: | ||
| * - Environment (test/prod) | ||
| * - Activation code | ||
| * - Encrypted wallet passphrase from Box D of keycard | ||
| * | ||
| * You need to install node and BitGoJS SDK to run this script. | ||
| * | ||
| * To install node, you can follow the instructions here: https://nodejs.org/en/download | ||
| * | ||
| * To install BitGoJS SDK, you can use the following command: | ||
| * npm install @bitgo/sdk-api | ||
| * | ||
| * Usage: | ||
| * tsx wallet-passphrase-recovery.ts | ||
| * OR | ||
| * npx ts-node wallet-passphrase-recovery.ts | ||
| */ | ||
|
|
||
| import { BitGoAPI } from '@bitgo/sdk-api'; | ||
| import * as readline from 'readline'; | ||
|
|
||
| // Create readline interface for user input | ||
| const rl = readline.createInterface({ | ||
| input: process.stdin, | ||
| output: process.stdout, | ||
| }); | ||
|
|
||
| // Function to ask questions in the terminal | ||
| function askQuestion(query: string): Promise<string> { | ||
| return new Promise((resolve) => { | ||
| rl.question(query, (answer) => { | ||
| resolve(answer); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| async function main(): Promise<void> { | ||
| try { | ||
| console.log('BitGo V1 Wallet Password Recovery Tool'); | ||
| console.log('====================================\n'); | ||
|
|
||
| // Get environment setting | ||
| const envInput = await askQuestion( | ||
| 'Enter environment (test/prod) [default: test]: ', | ||
| ); | ||
| const env = envInput.toLowerCase() === 'prod' ? 'prod' : 'test'; | ||
|
|
||
| // Initialize BitGo | ||
| const bitgo = new BitGoAPI({ | ||
| env: env, | ||
| }); | ||
|
|
||
| // Get activation code | ||
| const activationCode = await askQuestion('Enter activation code: '); | ||
|
|
||
| // Get encrypted wallet passphrase from Box D | ||
| const encryptedWalletPassphrase = await askQuestion( | ||
| 'Enter encrypted wallet passphrase from Box D: ', | ||
| ); | ||
|
|
||
| // Decrypt the wallet passphrase | ||
| const walletPassphrase = bitgo.decrypt({ | ||
| input: encryptedWalletPassphrase, | ||
| password: activationCode, | ||
| }); | ||
|
|
||
| console.log(`\n✅ SUCCESS: the decrypted passphrase is: ${walletPassphrase}`); | ||
| } catch (error) { | ||
| console.error(`\nError: ${error.message}`); | ||
| if (error.status) { | ||
| console.error(`Status code: ${error.status}`); | ||
| } | ||
| console.error('Please check your credentials and try again.'); | ||
| } finally { | ||
| rl.close(); | ||
| } | ||
| } | ||
|
|
||
| main().catch((error) => { | ||
| console.error(`Fatal error: ${error.message}`); | ||
| process.exit(1); | ||
| }); | ||
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.