GithubHelp home page GithubHelp logo

sdk's Introduction

webwallet

npm install webwallet

sdk's People

Contributors

boolpath avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

hashtagcoin

sdk's Issues

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

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.