Skip to content

jellyfish-wallet-encrypted hd_node.ts implementation#480

Merged
fuxingloh merged 4 commits intomainfrom
fuxingloh/jellyfish-wallet-encrypted
Jul 22, 2021
Merged

jellyfish-wallet-encrypted hd_node.ts implementation#480
fuxingloh merged 4 commits intomainfrom
fuxingloh/jellyfish-wallet-encrypted

Conversation

@fuxingloh
Copy link
Contributor

@fuxingloh fuxingloh commented Jul 22, 2021

What kind of PR is this?:

/kind feature

What this PR does / why we need it:

  • jellyfish-wallet not to use 44'/${COIN_TYPE}'/${account}'/0/0 for non-hardened path derivation to allow encrypted wallet implementations to access public key without requiring private key
    • updated to ${account}/0/0
  • extended bip32.test.ts for better encrypted and mnemonic testing
  • fixed scrypt re-requiring hash when it's already encoded in EncryptedData

EncryptedMnemonicHdNode extends MnemonicHdNode with overrides to deriveNode to use promise-based derivation technique to allow privateKey to be decrypted.

export class EncryptedMnemonicHdNode extends MnemonicHdNode {
  constructor (
    path: string,
    chainCode: Buffer,
    options: Bip32Options,
    private readonly rootPubKey: Buffer,
    private readonly promisePrivKey: () => Promise<Buffer>
  ) {
  }
}

EncryptedHdNodeProvider comes with wordsToEncryptedData to encrypt a mnemonic words into encrypted format to use within EncryptedHdNodeProvider. The encrypted version is the hot implementation, where the mnemonic is the cold implementation.

export class EncryptedHdNodeProvider implements WalletHdNodeProvider<EncryptedMnemonicHdNode> {
  /**
   * @param {string[]} words to convert into EncryptedProviderData
   * @param {Bip32Options} options
   * @param {string} scrypt to encrypt mnemonic words
   * @param {string} passphrase to encrypt mnemonic words with
   * @return EncryptedProviderData with unencrypted "pubKey & chainCode" and scrypt encoded 'encryptedPrivKey'
   */
  static wordsToEncryptedData (words: string[], options: Bip32Options, scrypt: Scrypt, passphrase: string): EncryptedProviderData
}

You can initialize EncryptedHdNodeProvider with EncryptedProviderData , Scrypt and PromptPassphrase for prompting password.

export class EncryptedHdNodeProvider implements WalletHdNodeProvider<EncryptedMnemonicHdNode> {
  /**
   * @param {EncryptedProviderData} data with unencrypted "pubKey & chainCode" and scrypt encoded 'encryptedPrivKey'
   * @param {Bip32Options} options
   * @param {string} scrypt to decrypt encrypted private key
   * @param {PromptPassphrase} promptPassphrase for on-demand request passphrase to decrypt encrypted private key
   * @return EncryptedHdNodeProvider
   */
  static init (data: EncryptedProviderData, options: Bip32Options, scrypt: Scrypt, promptPassphrase: PromptPassphrase): EncryptedHdNodeProvider
}

Which issue(s) does this PR fixes?:

Fixes #344
Fixes #133

@qlty-cloud-legacy
Copy link

Code Climate has analyzed commit c11a0ad and detected 0 issues on this pull request.

View more on Code Climate.

@github-actions
Copy link

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
packages/jellyfish/dist/index.umd.js 21.34 KB (0%) 427 ms (0%) 175 ms (+2.13% 🔺) 602 ms

@codecov
Copy link

codecov bot commented Jul 22, 2021

Codecov Report

Merging #480 (c11a0ad) into main (4d353f6) will increase coverage by 0.02%.
The diff coverage is 97.36%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #480      +/-   ##
==========================================
+ Coverage   97.28%   97.31%   +0.02%     
==========================================
  Files         104      105       +1     
  Lines        3019     3052      +33     
  Branches      378      378              
==========================================
+ Hits         2937     2970      +33     
  Misses         82       82              
Impacted Files Coverage Δ
packages/jellyfish-wallet/src/wallet_account.ts 100.00% <ø> (ø)
packages/jellyfish-wallet-encrypted/src/scrypt.ts 93.65% <66.66%> (ø)
packages/jellyfish-wallet-encrypted/src/hd_node.ts 100.00% <100.00%> (ø)
packages/jellyfish-wallet-encrypted/src/index.ts 100.00% <100.00%> (ø)
packages/jellyfish-wallet/src/wallet.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4d353f6...c11a0ad. Read the comment docs.

@fuxingloh fuxingloh marked this pull request as ready for review July 22, 2021 10:37
@monstrobishi monstrobishi enabled auto-merge (squash) July 22, 2021 12:30
@fuxingloh fuxingloh disabled auto-merge July 22, 2021 12:31
@fuxingloh fuxingloh merged commit ad6e422 into main Jul 22, 2021
@fuxingloh fuxingloh deleted the fuxingloh/jellyfish-wallet-encrypted branch July 22, 2021 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature New feature request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

jellyfish-wallet-mnemonic to support encrypt and decrypt

4 participants