bitcoinjs-lib
Advanced tools
Comparing version 3.2.1 to 3.3.0
{ | ||
"name": "bitcoinjs-lib", | ||
"version": "3.2.1", | ||
"version": "3.3.0", | ||
"description": "Client-side Bitcoin JavaScript library", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.js", |
@@ -15,3 +15,3 @@ var bip66 = require('bip66') | ||
ECSignature.parseCompact = function (buffer) { | ||
if (buffer.length !== 65) throw new Error('Invalid signature length') | ||
typeforce(types.BufferN(65), buffer) | ||
@@ -23,13 +23,19 @@ var flagByte = buffer.readUInt8(0) - 27 | ||
var recoveryParam = flagByte & 3 | ||
var signature = ECSignature.fromRSBuffer(buffer.slice(1)) | ||
var r = BigInteger.fromBuffer(buffer.slice(1, 33)) | ||
var s = BigInteger.fromBuffer(buffer.slice(33)) | ||
return { | ||
compressed: compressed, | ||
i: recoveryParam, | ||
signature: new ECSignature(r, s) | ||
signature: signature | ||
} | ||
} | ||
ECSignature.fromRSBuffer = function (buffer) { | ||
typeforce(types.BufferN(64), buffer) | ||
var r = BigInteger.fromBuffer(buffer.slice(0, 32)) | ||
var s = BigInteger.fromBuffer(buffer.slice(32, 64)) | ||
return new ECSignature(r, s) | ||
} | ||
ECSignature.fromDER = function (buffer) { | ||
@@ -65,5 +71,3 @@ var decode = bip66.decode(buffer) | ||
buffer.writeUInt8(i, 0) | ||
this.r.toBuffer(32).copy(buffer, 1) | ||
this.s.toBuffer(32).copy(buffer, 33) | ||
this.toRSBuffer(buffer, 1) | ||
return buffer | ||
@@ -79,2 +83,9 @@ } | ||
ECSignature.prototype.toRSBuffer = function (buffer, offset) { | ||
buffer = buffer || Buffer.alloc(64) | ||
this.r.toBuffer(32).copy(buffer, offset) | ||
this.s.toBuffer(32).copy(buffer, offset + 32) | ||
return buffer | ||
} | ||
ECSignature.prototype.toScriptSignature = function (hashType) { | ||
@@ -81,0 +92,0 @@ var hashTypeMod = hashType & ~0x80 |
@@ -670,3 +670,4 @@ var Buffer = require('safe-buffer').Buffer | ||
TransactionBuilder.prototype.sign = function (vin, keyPair, redeemScript, hashType, witnessValue, witnessScript) { | ||
if (keyPair.network !== this.network) throw new Error('Inconsistent network') | ||
// TODO: remove keyPair.network matching in 4.0.0 | ||
if (keyPair.network && keyPair.network !== this.network) throw new TypeError('Inconsistent network') | ||
if (!this.inputs[vin]) throw new Error('No input at index: ' + vin) | ||
@@ -684,3 +685,3 @@ hashType = hashType || Transaction.SIGHASH_ALL | ||
var kpPubKey = keyPair.getPublicKeyBuffer() | ||
var kpPubKey = keyPair.publicKey || keyPair.getPublicKeyBuffer() | ||
if (!canSign(input)) { | ||
@@ -704,2 +705,3 @@ if (witnessValue !== undefined) { | ||
} | ||
// enforce in order signing of public keys | ||
@@ -709,6 +711,9 @@ var signed = input.pubKeys.some(function (pubKey, i) { | ||
if (input.signatures[i]) throw new Error('Signature already exists') | ||
if (!keyPair.compressed && | ||
if (kpPubKey.length !== 33 && | ||
input.signType === scriptTypes.P2WPKH) throw new Error('BIP143 rejects uncompressed public keys in P2WPKH or P2WSH') | ||
input.signatures[i] = keyPair.sign(signatureHash).toScriptSignature(hashType) | ||
var signature = keyPair.sign(signatureHash) | ||
if (Buffer.isBuffer(signature)) signature = ECSignature.fromRSBuffer(signature) | ||
input.signatures[i] = signature.toScriptSignature(hashType) | ||
return true | ||
@@ -715,0 +720,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
117113
2785