Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

bitcore-lib-cash: Point does not lie on the curve #180

Closed
Gamaroff opened this issue Dec 6, 2017 · 7 comments
Closed

bitcore-lib-cash: Point does not lie on the curve #180

Gamaroff opened this issue Dec 6, 2017 · 7 comments

Comments

@Gamaroff
Copy link

Gamaroff commented Dec 6, 2017

When using the bitcore-lib-cash library the Error Point does not lie on the curve is thrown.

Using Typescript:

import BitcoreCash from 'bitcore-lib-cash';
let privateKey = new BitcoreCash.PrivateKey(); // throws Point does not lie on the curve 

Any pointers are much appreciated.

@arrix
Copy link

arrix commented Jan 17, 2018

Are you using bitcore-lib and bitcore-lib-cash at the same time?

I can generate PrivateKeys and Addresses without any problem if I use bitcore-lib-cash alone. However, if both libs are imported, I get Error: Point does not lie on the curve when pk.toPublicKey() is called

var bch = require('bitcore-lib-cash')
var bc = require('bitcore-lib')

(new bch.PrivateKey).toPublicKey()
(new bc.PrivateKey).toPublicKey()

@sail0778
Copy link

sail0778 commented Jan 17, 2018 via email

@Gamaroff
Copy link
Author

Thanks @arrix.

The problem was because I was using Bitcore Mnemonic with the bitcore-lib-cash and they were conflicting.

Bitcore Mnemonic uses bitcore-lib as a dependency.
Will there be a fix for that?

@arrix
Copy link

arrix commented Jan 17, 2018

The conflict may be worked around by requiring the two libs in specific order.

// Error: Point does not lie on the curve
var bch = require('bitcore-lib-cash')
var bc = require('bitcore-lib')

(new bch.PrivateKey).toPublicKey()
(new bc.PrivateKey).toPublicKey()

Note that bitcore-lib-cash/lib/publickey.js called into bitcore-lib/lib/crypto/point.js.

Error: Point does not lie on the curve
at Point.validate (/xxx/node_modules/bitcore-lib/lib/crypto/point.js:119:11)
at new PublicKey (/xxx/node_modules/bitcore-lib-cash/lib/publickey.js:53:14)
at Function.PublicKey.fromPrivateKey (/xxx/node_modules/bitcore-lib-cash/lib/publickey.js:221:10)
at PrivateKey.toPublicKey (/xxx/node_modules/bitcore-lib-cash/lib/privatekey.js:362:30)

If bitcore-lib is required before bitcore-lib-cash, it seems to work.

// seems to work
var bc = require('bitcore-lib')
var bch = require('bitcore-lib-cash')

(new bch.PrivateKey).toAddress()
(new bc.PrivateKey).toAddress()

@Gamaroff
Copy link
Author

Gamaroff commented Jan 17, 2018 via email

@Gamaroff
Copy link
Author

Thank you, @arrix
I can confirm that it does indeed work with mnemonic now.

Thank you for the help!

@mohammadrafigh
Copy link

@Gamaroff be aware that this workaround may break some internal checks for point, public key, etc. the right solution has been provided in #238 also that PR should consider the same approach for bn.js IMO.

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

No branches or pull requests

5 participants
@Gamaroff @arrix @mohammadrafigh @sail0778 and others