|
| 1 | +#!/usr/bin/env node |
| 2 | +/** |
| 3 | + * Wallet Passphrase Recovery Script |
| 4 | + * |
| 5 | + * This script takes box D information in the keycard and recovers the wallet passphrase. |
| 6 | + * |
| 7 | + * The script will prompt for: |
| 8 | + * - Environment (test/prod) |
| 9 | + * - Activation code |
| 10 | + * - Encrypted wallet passphrase from Box D of keycard |
| 11 | + * |
| 12 | + * You need to install node and BitGoJS SDK to run this script. |
| 13 | + * |
| 14 | + * To install node, you can follow the instructions here: https://nodejs.org/en/download |
| 15 | + * |
| 16 | + * To install BitGoJS SDK, you can use the following command: |
| 17 | + * npm install @bitgo/sdk-api |
| 18 | + * |
| 19 | + * Usage: |
| 20 | + * tsx wallet-passphrase-recovery.ts |
| 21 | + * OR |
| 22 | + * npx ts-node wallet-passphrase-recovery.ts |
| 23 | + */ |
| 24 | + |
| 25 | +import { BitGoAPI } from '@bitgo/sdk-api'; |
| 26 | +import * as readline from 'readline'; |
| 27 | + |
| 28 | +// Create readline interface for user input |
| 29 | +const rl = readline.createInterface({ |
| 30 | + input: process.stdin, |
| 31 | + output: process.stdout, |
| 32 | +}); |
| 33 | + |
| 34 | +// Function to ask questions in the terminal |
| 35 | +function askQuestion(query: string): Promise<string> { |
| 36 | + return new Promise((resolve) => { |
| 37 | + rl.question(query, (answer) => { |
| 38 | + resolve(answer); |
| 39 | + }); |
| 40 | + }); |
| 41 | +} |
| 42 | + |
| 43 | +async function main(): Promise<void> { |
| 44 | + try { |
| 45 | + console.log('BitGo V1 Wallet Password Recovery Tool'); |
| 46 | + console.log('====================================\n'); |
| 47 | + |
| 48 | + // Get environment setting |
| 49 | + const envInput = await askQuestion( |
| 50 | + 'Enter environment (test/prod) [default: test]: ', |
| 51 | + ); |
| 52 | + const env = envInput.toLowerCase() === 'prod' ? 'prod' : 'test'; |
| 53 | + |
| 54 | + // Initialize BitGo |
| 55 | + const bitgo = new BitGoAPI({ |
| 56 | + env: env, |
| 57 | + }); |
| 58 | + |
| 59 | + // Get activation code |
| 60 | + const activationCode = await askQuestion('Enter activation code: '); |
| 61 | + |
| 62 | + // Get encrypted wallet passphrase from Box D |
| 63 | + const encryptedWalletPassphrase = await askQuestion( |
| 64 | + 'Enter encrypted wallet passphrase from Box D: ', |
| 65 | + ); |
| 66 | + |
| 67 | + // Decrypt the wallet passphrase |
| 68 | + const walletPassphrase = bitgo.decrypt({ |
| 69 | + input: encryptedWalletPassphrase, |
| 70 | + password: activationCode, |
| 71 | + }); |
| 72 | + |
| 73 | + console.log(`\n✅ SUCCESS: the decrypted passphrase is: ${walletPassphrase}`); |
| 74 | + } catch (error) { |
| 75 | + console.error(`\nError: ${error.message}`); |
| 76 | + if (error.status) { |
| 77 | + console.error(`Status code: ${error.status}`); |
| 78 | + } |
| 79 | + console.error('Please check your credentials and try again.'); |
| 80 | + } finally { |
| 81 | + rl.close(); |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +main().catch((error) => { |
| 86 | + console.error(`Fatal error: ${error.message}`); |
| 87 | + process.exit(1); |
| 88 | +}); |
0 commit comments