bitcore-lib-cash
Advanced tools
Comparing version 8.14.4 to 8.15.0
@@ -22,2 +22,3 @@ 'use strict'; | ||
bitcore.crypto.ECDSA = require('./lib/crypto/ecdsa'); | ||
bitcore.crypto.Schnorr = require('./lib/crypto/schnorr'); | ||
bitcore.crypto.Hash = require('./lib/crypto/hash'); | ||
@@ -24,0 +25,0 @@ bitcore.crypto.Random = require('./lib/crypto/random'); |
@@ -152,2 +152,16 @@ 'use strict'; | ||
// todo: needs test case | ||
Point.prototype.hasSquare = function() { | ||
return !this.isInfinity() && this.isSquare(this.getY()); | ||
} | ||
// todo: needs test cases | ||
Point.prototype.isSquare = function(x) { | ||
let p = new BN('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F', 'hex'); | ||
let x0 = new BN(x); | ||
let base = x0.toRed(BN.red(p)); | ||
let res = base.redPow(p.sub(BN.One).div(new BN(2))).fromRed(); //refactor to BN arithmetic operations | ||
return res.eq(new BN(1)); | ||
} | ||
module.exports = Point; |
@@ -9,5 +9,5 @@ 'use strict'; | ||
var Signature = function Signature(r, s) { | ||
var Signature = function Signature(r, s, isSchnorr) { | ||
if (!(this instanceof Signature)) { | ||
return new Signature(r, s); | ||
return new Signature(r, s, isSchnorr); | ||
} | ||
@@ -17,3 +17,4 @@ if (r instanceof BN) { | ||
r: r, | ||
s: s | ||
s: s, | ||
isSchnorr: isSchnorr, | ||
}); | ||
@@ -33,3 +34,4 @@ } else if (r) { | ||
this.compressed = typeof obj.compressed !== 'undefined' ? | ||
obj.compressed : this.compressed; //whether the recovered pubkey is compressed | ||
obj.compressed : this.compressed; // whether the recovered pubkey is compressed | ||
this.isSchnorr = obj.isSchnorr; | ||
this.nhashtype = obj.nhashtype || this.nhashtype || undefined; | ||
@@ -67,2 +69,12 @@ return this; | ||
Signature.fromDER = Signature.fromBuffer = function(buf, strict) { | ||
// Schnorr Signatures use 64/65 byte for in tx r [len] 32 , s [len] 32, nhashtype | ||
if((buf.length === 64 || buf.length === 65)) { | ||
let obj = Signature.parseSchnorrEncodedSig(buf); | ||
let sig = new Signature(); | ||
sig.r = obj.r; | ||
sig.s = obj.s; | ||
sig.isSchnorr = true; | ||
return sig; | ||
} | ||
var obj = Signature.parseDER(buf, strict); | ||
@@ -97,2 +109,3 @@ var sig = new Signature(); | ||
var buf = Buffer.from(str, 'hex'); | ||
return Signature.fromDER(buf); | ||
@@ -102,2 +115,19 @@ }; | ||
Signature.parseSchnorrEncodedSig = function(buf) { | ||
let r = buf.slice(0,32); | ||
let s = buf.slice(32, 64); | ||
let hashtype; | ||
if (buf.length === 65) { | ||
hashtype = buf.slice(64,66); | ||
this.hashtype = hashtype; | ||
} | ||
var obj = { | ||
r: BN.fromBuffer(r), | ||
s: BN.fromBuffer(s) | ||
}; | ||
return obj; | ||
}; | ||
/** | ||
@@ -187,2 +217,6 @@ * In order to mimic the non-strict DER encoding of OpenSSL, set strict = false. | ||
if(this.isSchnorr) { | ||
return Buffer.concat([rnbuf, snbuf]); | ||
} | ||
var rneg = rnbuf[0] & 0x80 ? true : false; | ||
@@ -189,0 +223,0 @@ var sneg = snbuf[0] & 0x80 ? true : false; |
@@ -13,2 +13,3 @@ 'use strict'; | ||
var ECDSA = require('../crypto/ecdsa'); | ||
var Schnorr = require('../crypto/schnorr'); | ||
var $ = require('../util/preconditions'); | ||
@@ -163,3 +164,3 @@ var BufferUtil = require('../util/buffer'); | ||
var Input = require('./input'); | ||
if (_.isUndefined(flags)){ | ||
@@ -230,3 +231,3 @@ flags = DEFAULT_SIGN_FLAGS; | ||
} | ||
if (sighashType & Signature.SIGHASH_ANYONECANPAY) { | ||
@@ -255,8 +256,16 @@ txcopy.inputs = [txcopy.inputs[inputNumber]]; | ||
* @param {satoshisBN} input's amount | ||
* @param {signingMethod} signingMethod "ecdsa" or "schnorr" to sign a tx | ||
* @return {Signature} | ||
*/ | ||
function sign(transaction, privateKey, sighashType, inputIndex, subscript, satoshisBN, flags) { | ||
function sign(transaction, privateKey, sighashType, inputIndex, subscript, satoshisBN, flags, signingMethod) { | ||
var hashbuf = sighash(transaction, sighashType, inputIndex, subscript, satoshisBN, flags); | ||
signingMethod = signingMethod || "ecdsa"; | ||
if (signingMethod === "schnorr") { | ||
let sig = Schnorr.sign(hashbuf, privateKey, 'big').set({ | ||
nhashtype: sighashType | ||
}); | ||
return sig; | ||
} | ||
@@ -266,2 +275,3 @@ var sig = ECDSA.sign(hashbuf, privateKey, 'little').set({ | ||
}); | ||
return sig; | ||
@@ -281,8 +291,16 @@ } | ||
* @param {flags} verification flags | ||
* @param {signingMethod} signingMethod "ecdsa" or "schnorr" to sign a tx | ||
* @return {boolean} | ||
*/ | ||
function verify(transaction, signature, publicKey, inputIndex, subscript, satoshisBN, flags) { | ||
function verify(transaction, signature, publicKey, inputIndex, subscript, satoshisBN, flags, signingMethod) { | ||
$.checkArgument(!_.isUndefined(transaction)); | ||
$.checkArgument(!_.isUndefined(signature) && !_.isUndefined(signature.nhashtype)); | ||
var hashbuf = sighash(transaction, signature.nhashtype, inputIndex, subscript, satoshisBN, flags); | ||
signingMethod = signingMethod || "ecdsa"; | ||
if (signingMethod === "schnorr") { | ||
return Schnorr.verify(hashbuf, signature, publicKey, 'big'); | ||
} | ||
return ECDSA.verify(hashbuf, signature, publicKey, 'little'); | ||
@@ -289,0 +307,0 @@ } |
{ | ||
"name": "bitcore-lib-cash", | ||
"version": "8.14.4", | ||
"version": "8.15.0", | ||
"description": "A pure and powerful JavaScript Bitcoin Cash library.", | ||
@@ -39,3 +39,3 @@ "author": "BitPay <dev@bitpay.com>", | ||
"dependencies": { | ||
"bitcore-lib": "^8.14.4", | ||
"bitcore-lib": "^8.15.0", | ||
"bn.js": "=4.11.8", | ||
@@ -50,3 +50,3 @@ "bs58": "^4.0.1", | ||
"base-x": "=3.0.4", | ||
"bitcore-build": "^8.14.4", | ||
"bitcore-build": "^8.15.0", | ||
"brfs": "^2.0.1", | ||
@@ -53,0 +53,0 @@ "chai": "^4.2.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2465421
146
31572
Updatedbitcore-lib@^8.15.0