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

Wallet: enable seed phrase recovery from API #1023

Closed
pinheadmz opened this issue Aug 2, 2021 · 1 comment · Fixed by #1025
Closed

Wallet: enable seed phrase recovery from API #1023

pinheadmz opened this issue Aug 2, 2021 · 1 comment · Fixed by #1025

Comments

@pinheadmz
Copy link
Member

The bcoin API does not have a method to return a wallet's seed phrase once the wallet has been encrypted. That means that if a user creates a wallet and encrypts in the same command (i.e. mkwallet --passphrase=...) they will not be able to back up their seed phrase!

One possible way to do this might be switching the JSON function by this.key instead of this.encrypted:

toJSON(network, unsafe) {
if (this.encrypted) {
return {
encrypted: true,
until: this.until,
iv: this.iv.toString('hex'),
ciphertext: unsafe ? this.ciphertext.toString('hex') : undefined,
algorithm: MasterKey.algByVal[this.alg].toLowerCase(),
n: this.n,
r: this.r,
p: this.p
};
}
return {
encrypted: false,
key: unsafe ? this.key.toJSON(network) : undefined,
mnemonic: unsafe && this.mnemonic ? this.mnemonic.toJSON() : undefined
};
}

this.encrypted is a property of the wallet that never changes once a passphrase has been set. this.key is null by default and only contains a value (the wallets unencrypted private key) when the wallet is unlocked.

I tried making this change locally and seems to work as expected:

--> bwallet-cli --network=regtest --id=two  master
{
  "encrypted": true,
  "until": 0,
  "iv": "349e254a48767ce61a24a15da179fc61",
  "ciphertext": "49e5335079c08e59bffe1946bab0f1d75f9cca39a98fe08e99990090a89e7eade58d46fe2f40d35988daa3922481bcabbf6209cc1dbe340ebdbfb9288bcdba10834117f39f62cff43ad9dd35e71596fa7bb7e6f894e6d2892b4c5b264a55f01f",
  "algorithm": "pbkdf2",
  "n": 50000,
  "r": 0,
  "p": 0
}

--> bwallet-cli --network=regtest --id=two  unlock wow123
Unlocked.

--> bwallet-cli --network=regtest --id=two  master
{
  "encrypted": false,
  "key": {
    "xprivkey": "tprv8ZgxMBicQKsPdUW9zaJrkwLy2gMMsVQLPqT47Y3fhXUqn3TGHCwiPEBjGxvxzEySL9YuBjgLYxU2vmQeJFJgaUde7UcqWvVFKpLpX11q8Je"
  },
  "mnemonic": {
    "bits": 128,
    "language": "english",
    "entropy": "e3e7496235b8fc43166a4dcc4b5b9986",
    "phrase": "token demise flat hidden more canoe fluid endless slush food toy artwork"
  }
}

--> bwallet-cli --network=regtest --id=two  lock
Locked.

--> bwallet-cli --network=regtest --id=two  master
{
  "encrypted": true,
  "until": 0,
  "iv": "349e254a48767ce61a24a15da179fc61",
  "ciphertext": "49e5335079c08e59bffe1946bab0f1d75f9cca39a98fe08e99990090a89e7eade58d46fe2f40d35988daa3922481bcabbf6209cc1dbe340ebdbfb9288bcdba10834117f39f62cff43ad9dd35e71596fa7bb7e6f894e6d2892b4c5b264a55f01f",
  "algorithm": "pbkdf2",
  "n": 50000,
  "r": 0,
  "p": 0
}
@pinheadmz
Copy link
Member Author

testing webhooks bcoin 222

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant