Skip to content
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

Keystore support for Import #699

Closed
twblack88 opened this issue Dec 9, 2024 · 1 comment · Fixed by #703
Closed

Keystore support for Import #699

twblack88 opened this issue Dec 9, 2024 · 1 comment · Fixed by #703
Assignees

Comments

@twblack88
Copy link

twblack88 commented Dec 9, 2024

We need the ability to import keystores. Handle file upload, add password, and then decrypt.

Need to spike on the security from native store with the Mnemonic vs. plaintext. Bonus points if we can figure out how to export both the keystore & native wallet seed.

Flow with new wallet flow:
https://www.figma.com/design/om2yDg0BjLNNSkJz82O30N/Wallet-Modal?node-id=2718-94&node-type=frame&t=c3Y9ABfz37WW1oiH-11
Flow with current wallet flow:
https://www.figma.com/file/auLL8w102VUd7ypMZNDjin?node-id=75:3202&locale=en&type=design

@twblack88 twblack88 changed the title Keystore support Keystore support for Import Dec 9, 2024
@twblack88
Copy link
Author

export const encryptMnemonic = (mnemonic: string, password: string): string => {
  const iv = crypto.randomBytes(16)
  const key = crypto.scryptSync(password, 'salt', 32)
  const cipher = crypto.createCipheriv('aes-256-cbc', key, iv)
  const encrypted = cipher.update(mnemonic, 'utf8', 'hex') + cipher.final('hex')
  return iv.toString('hex') + ':' + encrypted
}

const decryptMnemonic = (encryptedMnemonic: string, password: string): string | undefined => {
  try {
    const [ivHex, encryptedHex] = encryptedMnemonic.split(':')
    const iv = Buffer.from(ivHex, 'hex')
    const encrypted = Buffer.from(encryptedHex, 'hex')
    const key = crypto.scryptSync(password, 'salt', 32)
    const decipher = crypto.createDecipheriv('aes-256-cbc', key, iv)
    const decrypted = decipher.update(encrypted, undefined, 'utf8') + decipher.final('utf8')
    return decrypted
  } catch (err) {
    error('Failed to decrypt mnemonic.')
  }
}

pseudo cryptography algo to double check against thorswap, which is the biggest user of keystores (assuming AES 256 is the one)

@twblack88 twblack88 moved this to Up next / groomed in ShapeShift Dashboard Dec 9, 2024
@kaladinlight kaladinlight self-assigned this Dec 9, 2024
@gomesalexandre gomesalexandre self-assigned this Dec 24, 2024
@gomesalexandre gomesalexandre moved this from Up next / groomed to In review in ShapeShift Dashboard Dec 24, 2024
@github-project-automation github-project-automation bot moved this from In review to Done in ShapeShift Dashboard Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants