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

fix(core-json-rpc): retrieve bip38 wallet after creating it and return the encoded WIF #1652

Closed
wants to merge 3 commits into from

Conversation

zillionn
Copy link
Contributor

@zillionn zillionn commented Dec 5, 2018

Proposed changes

When there is no encryptedWif in the database:

const encryptedWif = await database.get(
utils.sha256(Buffer.from(userId)).toString('hex'),
)

the catch is returning encryptedWif not encoded:

const { publicKey, privateKey } = crypto.getKeys(bip39.generateMnemonic())
const encryptedWif = bip38.encrypt(
Buffer.from(privateKey, 'hex'),
true,
params.bip38 + params.userId,
)
await database.set(
utils.sha256(Buffer.from(params.userId)).toString('hex'),
encryptedWif,
)
return {
publicKey,
address: crypto.getAddress(publicKey),
wif: encryptedWif,
}

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (improve a current implementation without adding a new feature or fixing a bug)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Build (changes that affect the build system)
  • Docs (documentation only changes)
  • Test (adding missing tests or fixing existing tests)
  • Other... Please describe:

Checklist

  • I have read the CONTRIBUTING documentation
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

@zillionn
Copy link
Contributor Author

zillionn commented Dec 5, 2018

Please test! Sometimes I get this error:

{
"error": {
"code": -32603,
"data": "TypeError: privateKey.copy is not a function\n at encodeRaw (/home/darknodeuser/ark-core/node_modules/wif/index.js:33:14)\n at Object.encode (/home/darknodeuser/ark-core/node_modules/wif/index.js:47:60)\n at method (/home/darknodeuser/ark-core/packages/core-json-rpc/lib/server/methods/wallets/bip38/create.js:33:27)",
"message": "privateKey.copy is not a function"
},
"id": "unique-request-id",
"jsonrpc": "2.0"
}

@zillionn zillionn closed this Dec 5, 2018
@zillionn zillionn reopened this Dec 5, 2018
@zillionn
Copy link
Contributor Author

zillionn commented Dec 5, 2018

I'm giving up.

@zillionn zillionn closed this Dec 5, 2018
@alexbarnsley
Copy link
Member

No quitting :danstop:

@alexbarnsley alexbarnsley reopened this Dec 5, 2018
@ghost ghost assigned alexbarnsley Dec 5, 2018
@ghost ghost added the review label Dec 5, 2018
@zillionn
Copy link
Contributor Author

zillionn commented Dec 5, 2018

It's the stupid tests, I hate them! They just don't pass because this

const response = await request('wallets.bip38.create', {
bip38: 'this is a top secret passphrase',
userId,
})

returns this

data:
{ jsonrpc: '2.0',
id: '8612fcb3-e03a-4c38-8657-d41b9d8b6552',
error:
{ code: -32603,
message: 'privateKey.copy is not a function',
data:
'TypeError: privateKey.copy is not a function\n at encodeRaw (/Work/ark-core/node_modules/wif/index.js:33:14)\n at Object.encode (/Work/ark-core/node_modules/wif/index.js:47:60)\n at encode (/Work/ark-core/packages/core-json-rpc/lib/server/methods/wallets/bip38/create.js:34:29)' } } }

@ghost ghost assigned faustbrian Dec 5, 2018
@faustbrian
Copy link
Contributor

@zillionn adjusted it for you

@faustbrian faustbrian changed the title fix(json-rpc): bip38 wif generation fix(core-json-rpc): retrieve bip38 wallet after creating it and return the encoded WIF Dec 5, 2018
@zillionn
Copy link
Contributor Author

zillionn commented Dec 5, 2018

OK thanks, but will the tests pass???

@faustbrian
Copy link
Contributor

Closing this as it required more changes after looking at the full picture.

#1653

@faustbrian faustbrian closed this Dec 5, 2018
@ghost ghost removed the review label Dec 5, 2018
@zillionn zillionn deleted the json-rpc-wif-fix branch December 8, 2018 01:24
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 this pull request may close these issues.

3 participants