Skip to content

Commit 3342646

Browse files
committed
TxBuilder: add support for RSBuffer type keyPairs and .publicKey
1 parent 62e1f02 commit 3342646

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/transaction_builder.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ TransactionBuilder.prototype.sign = function (vin, keyPair, redeemScript, hashTy
680680
throw new Error('Inconsistent redeemScript')
681681
}
682682

683-
var kpPubKey = keyPair.getPublicKeyBuffer()
683+
var kpPubKey = keyPair.publicKey || keyPair.getPublicKeyBuffer()
684684
if (!canSign(input)) {
685685
if (witnessValue !== undefined) {
686686
if (input.value !== undefined && input.value !== witnessValue) throw new Error('Input didn\'t match witnessValue')
@@ -699,14 +699,18 @@ TransactionBuilder.prototype.sign = function (vin, keyPair, redeemScript, hashTy
699699
} else {
700700
signatureHash = this.tx.hashForSignature(vin, input.signScript, hashType)
701701
}
702+
702703
// enforce in order signing of public keys
703704
var signed = input.pubKeys.some(function (pubKey, i) {
704705
if (!kpPubKey.equals(pubKey)) return false
705706
if (input.signatures[i]) throw new Error('Signature already exists')
706-
if (!keyPair.compressed &&
707+
if (kpPubKey.length !== 33 &&
707708
input.signType === scriptTypes.P2WPKH) throw new Error('BIP143 rejects uncompressed public keys in P2WPKH or P2WSH')
708709

709-
input.signatures[i] = keyPair.sign(signatureHash).toScriptSignature(hashType)
710+
var signature = keyPair.sign(signatureHash)
711+
if (Buffer.isBuffer(signature)) signature = ECSignature.fromRSBuffer(signature)
712+
713+
input.signatures[i] = signature.toScriptSignature(hashType)
710714
return true
711715
})
712716

0 commit comments

Comments
 (0)