Skip to content

message: return base64 for sign, make verify work with base64 string #230

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

Closed
wants to merge 1 commit into from

Conversation

kyledrake
Copy link
Contributor

This PR is related to #217.

This returns a base64 signature for Message.sign, and allows verify to work with a base64 string (or a buffer). It's using the existing test suite and fixtures.

I'm more than a little confused about the standardization around base64 here, but it does seem to be the convention for everyone using it. Noteworthy is that we actually reduce test code because the fixture signatures are in base64.

We could also make a helper function (ala signBase64) instead, if we preferred to return a buffer here. But we should definitely provide an easy way for people to do this, since it seems to be common usage.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.0%) when pulling 8d62715 on coinpunk:verifybase64 into 6596ca1 on bitcoinjs:master.

function verify(address, signatureBuffer, message, network) {
function verify(address, signature, message, network) {
if(!Buffer.isBuffer(signature))
var signature = new Buffer(signature, 'base64')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add the {} and get rid of the variable re-declaration please?

@dcousens
Copy link
Contributor

This is again just sidestepping the issue that because devs don't have exposure to Buffer, we start unnecessarily converting back and forth for them. I'd prefer to wait on the outcome of #231 before we merge this.

@@ -31,18 +31,21 @@ function sign(privKey, message, network) {
var e = BigInteger.fromBuffer(hash)
var i = ecdsa.calcPubKeyRecoveryParam(ecparams, e, signature, privKey.pub.Q)

return signature.toCompact(i, privKey.pub.compressed)
return signature.toCompact(i, privKey.pub.compressed).toString('base64')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am happy to merge without this change and other fixes applied.

@dcousens
Copy link
Contributor

Closed in favour of #266 unless @kyledrake comes out of the woodwork to fix the issues.

@dcousens dcousens closed this Aug 20, 2014
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.

4 participants