You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1017 B

  1. // Copyright (c) 2018-2020, Zpalmtree
  2. //
  3. // Please see the included LICENSE file for more information.
  4. import * as fs from 'fs';
  5. import { WalletError, WalletErrorCode } from './WalletError';
  6. import { WalletEncryption } from './WalletEncryption';
  7. /**
  8. * Open the wallet from the given filename with the given password and return
  9. * a JSON string. Uses pbkdf2 encryption, not the same as fedoragold-service
  10. *
  11. * Returns the JSON, and an error. If error is not undefined, the JSON will
  12. * be an empty string.
  13. */
  14. export function openWallet(filename: string, password: string): [string, WalletError | undefined] {
  15. let data: Buffer;
  16. console.log("openWallet: "+filename);
  17. try {
  18. data = fs.readFileSync(filename);
  19. } catch (err) {
  20. let strErr = "Error in openWallet";
  21. if (err instanceof Error) strErr = err.toString();
  22. return ['', new WalletError(WalletErrorCode.FILENAME_NON_EXISTENT, strErr)];
  23. }
  24. return WalletEncryption.decryptWalletFromBuffer(data, password);
  25. }