bitpay / bitcore-lib

A pure and powerful JavaScript Bitcoin library
https://bitcore.io/
Other
613 stars 1.03k forks source link

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

Closed Gamaroff closed 6 years ago

Gamaroff commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

how to generate privatekey and adress can u tell me step by step and where i can get sofware

regards

On Wed, Jan 17, 2018 at 1:31 PM, arrix notifications@github.com wrote:

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 bc = require('bitcore-lib')

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

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/bitpay/bitcore-lib/issues/180#issuecomment-358210845, or mute the thread https://github.com/notifications/unsubscribe-auth/AhnILSMSZ9q7bmrLchvYdvYWBI3vcd5Rks5tLZPMgaJpZM4Q3s2X .

Gamaroff commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

Cool thanks!

I'll give it a try.

On Wed, Jan 17, 2018 at 10:59 AM, arrix notifications@github.com wrote:

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()

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bitpay/bitcore-lib/issues/180#issuecomment-358239467, or mute the thread https://github.com/notifications/unsubscribe-auth/AAOfhpreKItvYxAdayRrIV3wqwG015-dks5tLbaPgaJpZM4Q3s2X .

Gamaroff commented 6 years ago

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

Thank you for the help!

mohammadrafigh commented 5 years ago

@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.