Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Change in the encoding of public key for hex string to be compatible with webwallet sdk version #2

Open
ivancho98 opened this issue Aug 11, 2018 · 0 comments

Comments

@ivancho98
Copy link

After generating the keypair in the src/keypair.js , the keypair.getPublic('hex') encodes the public key using the method getPublic for lib/elliptic/ec/key.js

KeyPair.prototype.getPublic = function getPublic(compact, enc) {
  // compact is optional argument
  if (typeof compact === 'string') {
    enc = compact;
    compact = null;
  }

  if (!this.pub)
    this.pub = this.ec.g.mul(this.priv);

  if (!enc)
    return this.pub;

  return this.pub.encode(enc, compact);
};

But in order to be compatible with https://github.com/minkainc/webwallet-sdk-java version it should use the lib/elliptic/eddsa/key.js

KeyPair.prototype.getPublic = function getPublic(enc) {
  return utils.encode(this.pubBytes(), enc);
};

So my proposal is to change the implementation of the keypair.js to :

'use strict'

const elliptic = require('elliptic')
const ed25519 = new elliptic.ec('ed25519')
const eddsa = elliptic.eddsa;

const schemes = {
  ed25519: {
    generate: ({ compressed = false } = {}) => {
      let keypair = ed25519.genKeyPair()

      let eddsaWithed25519 = new eddsa('ed25519');

      let keyPairEddsa = eddsaWithed25519.keyFromSecret(keypair.getPrivate());

      return {
        scheme: 'ed25519',
        public: keyPairEddsa.getPublic('hex'),
        secret: keypair.getPrivate('hex')
      }
    }
  }
}

class KeyPair {
  static generate(options = {}) {
    let {scheme = 'ed25519'} = options
    if (!schemes[scheme]) throw new Error('invalid-scheme')

    return schemes[scheme].generate(options)
  }
}

module.exports = KeyPair

Certainly there are some other changes and adequations that need to be made in Address and Signature.

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

No branches or pull requests

1 participant