expose signer through TxSigner
This commit is contained in:
parent
155c9afe05
commit
fdcd277ba9
@ -37,6 +37,7 @@ txb.addOutput(myaddress, txOut.value - 5000)
|
|||||||
|
|
||||||
var unsigned = txb.buildIncomplete()
|
var unsigned = txb.buildIncomplete()
|
||||||
var signer = new TxSigner(unsigned)
|
var signer = new TxSigner(unsigned)
|
||||||
|
|
||||||
signer.sign(0, root.keyPair, {
|
signer.sign(0, root.keyPair, {
|
||||||
scriptPubKey: txOut.script,
|
scriptPubKey: txOut.script,
|
||||||
redeemScript: toSegwitPubkey,
|
redeemScript: toSegwitPubkey,
|
||||||
|
|||||||
@ -110,6 +110,9 @@ function InSigner (tx, nIn, opts) {
|
|||||||
if ((tx instanceof Transaction) === false) {
|
if ((tx instanceof Transaction) === false) {
|
||||||
throw new Error('A transaction is required for InSigner')
|
throw new Error('A transaction is required for InSigner')
|
||||||
}
|
}
|
||||||
|
if (tx.ins[nIn] === undefined) {
|
||||||
|
throw new Error('No transaction input at this index')
|
||||||
|
}
|
||||||
if (opts.scriptPubKey === undefined) {
|
if (opts.scriptPubKey === undefined) {
|
||||||
throw new Error('A value for scriptPubKey is required')
|
throw new Error('A value for scriptPubKey is required')
|
||||||
}
|
}
|
||||||
@ -440,6 +443,12 @@ function TxSigner (tx) {
|
|||||||
this.states = []
|
this.states = []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TxSigner.prototype.signer = function (nIn, opts) {
|
||||||
|
if (this.states[nIn] === undefined) {
|
||||||
|
this.states[nIn] = new InSigner(this.tx, nIn, opts)
|
||||||
|
}
|
||||||
|
return this.states[nIn]
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Sign a transaction.
|
* Sign a transaction.
|
||||||
*
|
*
|
||||||
@ -456,11 +465,8 @@ TxSigner.prototype.sign = function (nIn, key, opts, sigHashType) {
|
|||||||
}
|
}
|
||||||
// You can probably make this work with the current library, if you can work out the witnessScript above!
|
// You can probably make this work with the current library, if you can work out the witnessScript above!
|
||||||
// generate opts for the internal signer based off older way of positional arguments to TxSigner.sign
|
// generate opts for the internal signer based off older way of positional arguments to TxSigner.sign
|
||||||
if (this.states[nIn] === undefined) {
|
|
||||||
this.states[nIn] = new InSigner(this.tx, nIn, opts)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.states[nIn].sign(key, sigHashType)) {
|
if (!this.signer(nIn, opts).sign(key, sigHashType)) {
|
||||||
throw new Error('Unsignable input: ', nIn)
|
throw new Error('Unsignable input: ', nIn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user