Promise fixes for async
This commit is contained in:
parent
539c88596a
commit
b98761a283
2 changed files with 38 additions and 30 deletions
31
src/psbt.js
31
src/psbt.js
|
@ -175,20 +175,23 @@ class Psbt extends bip174_1.Psbt {
|
|||
return this.addPartialSigToInput(inputIndex, partialSig);
|
||||
}
|
||||
signInputAsync(inputIndex, keyPair) {
|
||||
if (!keyPair || !keyPair.publicKey)
|
||||
throw new Error('Need Signer to sign input');
|
||||
const { hash, sighashType } = getHashAndSighashType(
|
||||
this.inputs,
|
||||
inputIndex,
|
||||
keyPair.publicKey,
|
||||
this.globalMap.unsignedTx,
|
||||
);
|
||||
return keyPair.sign(hash).then(signature => {
|
||||
const partialSig = {
|
||||
pubkey: keyPair.publicKey,
|
||||
signature: bscript.signature.encode(signature, sighashType),
|
||||
};
|
||||
this.addPartialSigToInput(inputIndex, partialSig);
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!keyPair || !keyPair.publicKey)
|
||||
return reject(new Error('Need Signer to sign input'));
|
||||
const { hash, sighashType } = getHashAndSighashType(
|
||||
this.inputs,
|
||||
inputIndex,
|
||||
keyPair.publicKey,
|
||||
this.globalMap.unsignedTx,
|
||||
);
|
||||
Promise.resolve(keyPair.sign(hash)).then(signature => {
|
||||
const partialSig = {
|
||||
pubkey: keyPair.publicKey,
|
||||
signature: bscript.signature.encode(signature, sighashType),
|
||||
};
|
||||
this.addPartialSigToInput(inputIndex, partialSig);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -214,23 +214,28 @@ export class Psbt extends PsbtBase {
|
|||
}
|
||||
|
||||
signInputAsync(inputIndex: number, keyPair: SignerAsync): Promise<void> {
|
||||
if (!keyPair || !keyPair.publicKey)
|
||||
throw new Error('Need Signer to sign input');
|
||||
const { hash, sighashType } = getHashAndSighashType(
|
||||
this.inputs,
|
||||
inputIndex,
|
||||
keyPair.publicKey,
|
||||
this.globalMap.unsignedTx!,
|
||||
return new Promise(
|
||||
(resolve, reject): void => {
|
||||
if (!keyPair || !keyPair.publicKey)
|
||||
return reject(new Error('Need Signer to sign input'));
|
||||
const { hash, sighashType } = getHashAndSighashType(
|
||||
this.inputs,
|
||||
inputIndex,
|
||||
keyPair.publicKey,
|
||||
this.globalMap.unsignedTx!,
|
||||
);
|
||||
|
||||
Promise.resolve(keyPair.sign(hash)).then(signature => {
|
||||
const partialSig = {
|
||||
pubkey: keyPair.publicKey,
|
||||
signature: bscript.signature.encode(signature, sighashType),
|
||||
};
|
||||
|
||||
this.addPartialSigToInput(inputIndex, partialSig);
|
||||
resolve();
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
return keyPair.sign(hash).then(signature => {
|
||||
const partialSig = {
|
||||
pubkey: keyPair.publicKey,
|
||||
signature: bscript.signature.encode(signature, sighashType),
|
||||
};
|
||||
|
||||
this.addPartialSigToInput(inputIndex, partialSig);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue