Condense sign parts work directly
This commit is contained in:
parent
84d5e67e38
commit
d814c21466
2 changed files with 50 additions and 52 deletions
|
@ -153,7 +153,8 @@ class TransactionBuilder {
|
|||
witnessValue,
|
||||
witnessScript,
|
||||
) {
|
||||
const data = getSigningData(
|
||||
trySign(
|
||||
getSigningData(
|
||||
this,
|
||||
signParams,
|
||||
keyPair,
|
||||
|
@ -161,16 +162,8 @@ class TransactionBuilder {
|
|||
hashType,
|
||||
witnessValue,
|
||||
witnessScript,
|
||||
);
|
||||
const { input, ourPubKey, signatureHash } = data;
|
||||
({ keyPair, hashType } = data);
|
||||
trySign(
|
||||
input,
|
||||
ourPubKey,
|
||||
keyPair,
|
||||
signatureHash,
|
||||
hashType,
|
||||
this.__USE_LOW_R,
|
||||
),
|
||||
);
|
||||
}
|
||||
__addInputUnsafe(txHash, vout, options) {
|
||||
|
@ -934,7 +927,14 @@ function checkSignArgs(txb, signParams) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
function trySign(input, ourPubKey, keyPair, signatureHash, hashType, useLowR) {
|
||||
function trySign({
|
||||
input,
|
||||
ourPubKey,
|
||||
keyPair,
|
||||
signatureHash,
|
||||
hashType,
|
||||
useLowR,
|
||||
}) {
|
||||
// enforce in order signing of public keys
|
||||
let signed = false;
|
||||
for (const [i, pubKey] of input.pubkeys.entries()) {
|
||||
|
@ -960,6 +960,7 @@ function getSigningData(
|
|||
hashType,
|
||||
witnessValue,
|
||||
witnessScript,
|
||||
useLowR,
|
||||
) {
|
||||
let vin;
|
||||
if (typeof signParams === 'number') {
|
||||
|
@ -1045,5 +1046,6 @@ function getSigningData(
|
|||
keyPair,
|
||||
signatureHash,
|
||||
hashType,
|
||||
useLowR: !!useLowR,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -243,7 +243,8 @@ export class TransactionBuilder {
|
|||
witnessValue?: number,
|
||||
witnessScript?: Buffer,
|
||||
): void {
|
||||
const data = getSigningData(
|
||||
trySign(
|
||||
getSigningData(
|
||||
this,
|
||||
signParams,
|
||||
keyPair,
|
||||
|
@ -251,18 +252,8 @@ export class TransactionBuilder {
|
|||
hashType,
|
||||
witnessValue,
|
||||
witnessScript,
|
||||
);
|
||||
|
||||
const { input, ourPubKey, signatureHash } = data;
|
||||
({ keyPair, hashType } = data);
|
||||
|
||||
trySign(
|
||||
input,
|
||||
ourPubKey,
|
||||
keyPair,
|
||||
signatureHash,
|
||||
hashType,
|
||||
this.__USE_LOW_R,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1161,14 +1152,14 @@ function checkSignArgs(txb: TransactionBuilder, signParams: TxbSignArg): void {
|
|||
}
|
||||
}
|
||||
|
||||
function trySign(
|
||||
input: TxbInput,
|
||||
ourPubKey: Buffer,
|
||||
keyPair: ECPairInterface,
|
||||
signatureHash: Buffer,
|
||||
hashType: number,
|
||||
useLowR: boolean,
|
||||
): void {
|
||||
function trySign({
|
||||
input,
|
||||
ourPubKey,
|
||||
keyPair,
|
||||
signatureHash,
|
||||
hashType,
|
||||
useLowR,
|
||||
}: SigningData): void {
|
||||
// enforce in order signing of public keys
|
||||
let signed = false;
|
||||
for (const [i, pubKey] of input.pubkeys!.entries()) {
|
||||
|
@ -1190,6 +1181,15 @@ function trySign(
|
|||
if (!signed) throw new Error('Key pair cannot sign for this input');
|
||||
}
|
||||
|
||||
interface SigningData {
|
||||
input: TxbInput;
|
||||
ourPubKey: Buffer;
|
||||
keyPair: ECPairInterface;
|
||||
signatureHash: Buffer;
|
||||
hashType: number;
|
||||
useLowR: boolean;
|
||||
}
|
||||
|
||||
function getSigningData(
|
||||
txb: TransactionBuilder,
|
||||
signParams: number | TxbSignArg,
|
||||
|
@ -1198,13 +1198,8 @@ function getSigningData(
|
|||
hashType?: number,
|
||||
witnessValue?: number,
|
||||
witnessScript?: Buffer,
|
||||
): {
|
||||
input: TxbInput;
|
||||
ourPubKey: Buffer;
|
||||
keyPair: ECPairInterface;
|
||||
signatureHash: Buffer;
|
||||
hashType: number;
|
||||
} {
|
||||
useLowR?: boolean,
|
||||
): SigningData {
|
||||
let vin: number;
|
||||
if (typeof signParams === 'number') {
|
||||
console.warn(
|
||||
|
@ -1302,5 +1297,6 @@ function getSigningData(
|
|||
keyPair,
|
||||
signatureHash,
|
||||
hashType,
|
||||
useLowR: !!useLowR,
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue