bitpay / bitcore-lib

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

Conflict between bitcore-lib and bitcore-lib-cash #192

Open arrix opened 6 years ago

arrix commented 6 years ago

There is a conflict between the two libs when used together. I found a work around by chaining the require() order. But it's worth digging the root cause to ensure correctness.

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

bitcore-lib 0.15.0 bitcore-lib-cash 0.16.1

mohammadrafigh commented 5 years ago

238 fixes this