Fix method names for PSBT

This commit is contained in:
junderw 2019-07-19 17:21:31 +09:00
parent f75aebc6f9
commit a3bfee75b0
No known key found for this signature in database
GPG key ID: B256185D3A971908
6 changed files with 25 additions and 18 deletions

View file

@ -1,3 +1,7 @@
# 5.1.1
__changed__
- Name inconsistencies for Psbt class. (Quick fix)
# 5.1.0 # 5.1.0
__added__ __added__
- A new `Psbt` class for creating, distributing, combining, signing, and compiling Transactions (#1425) - A new `Psbt` class for creating, distributing, combining, signing, and compiling Transactions (#1425)

View file

@ -42,7 +42,7 @@ const DEFAULT_OPTS = {
* data for updateOutput. * data for updateOutput.
* For a list of what attributes should be what types. Check the bip174 library. * For a list of what attributes should be what types. Check the bip174 library.
* Also, check the integration tests for some examples of usage. * Also, check the integration tests for some examples of usage.
* Signer: There are a few methods. signAllInputs and signAsync, which will search all input * Signer: There are a few methods. signAllInputs and signAllInputsAsync, which will search all input
* information for your pubkey or pubkeyhash, and only sign inputs where it finds * information for your pubkey or pubkeyhash, and only sign inputs where it finds
* your info. Or you can explicitly sign a specific input with signInput and * your info. Or you can explicitly sign a specific input with signInput and
* signInputAsync. For the async methods you can create a SignerAsync object * signInputAsync. For the async methods you can create a SignerAsync object
@ -295,7 +295,7 @@ class Psbt {
} }
return this; return this;
} }
signHDAsync( signAllInputsHDAsync(
hdKeyPair, hdKeyPair,
sighashTypes = [transaction_1.Transaction.SIGHASH_ALL], sighashTypes = [transaction_1.Transaction.SIGHASH_ALL],
) { ) {
@ -380,7 +380,10 @@ class Psbt {
} }
return this; return this;
} }
signAsync(keyPair, sighashTypes = [transaction_1.Transaction.SIGHASH_ALL]) { signAllInputsAsync(
keyPair,
sighashTypes = [transaction_1.Transaction.SIGHASH_ALL],
) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!keyPair || !keyPair.publicKey) if (!keyPair || !keyPair.publicKey)
return reject(new Error('Need Signer to sign input')); return reject(new Error('Need Signer to sign input'));

View file

@ -132,7 +132,7 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
signer2.signAllInputs(alice2.keys[0]); signer2.signAllInputs(alice2.keys[0]);
// If your signer object's sign method returns a promise, use the following // If your signer object's sign method returns a promise, use the following
// await signer2.signAsync(alice2.keys[0]) // await signer2.signAllInputsAsync(alice2.keys[0])
// encode to send back to combiner (signer 1 and 2 are not near each other) // encode to send back to combiner (signer 1 and 2 are not near each other)
const s1text = signer1.toBase64(); const s1text = signer1.toBase64();

View file

@ -219,14 +219,14 @@ describe(`Psbt`, () => {
}) })
}) })
describe('signAsync', () => { describe('signAllInputsAsync', () => {
fixtures.signInput.checks.forEach(f => { fixtures.signInput.checks.forEach(f => {
if (f.description === 'checks the input exists') return if (f.description === 'checks the input exists') return
it(f.description, async () => { it(f.description, async () => {
if (f.shouldSign) { if (f.shouldSign) {
const psbtThatShouldsign = Psbt.fromBase64(f.shouldSign.psbt) const psbtThatShouldsign = Psbt.fromBase64(f.shouldSign.psbt)
assert.doesNotReject(async () => { assert.doesNotReject(async () => {
await psbtThatShouldsign.signAsync( await psbtThatShouldsign.signAllInputsAsync(
ECPair.fromWIF(f.shouldSign.WIF), ECPair.fromWIF(f.shouldSign.WIF),
f.shouldSign.sighashTypes || undefined, f.shouldSign.sighashTypes || undefined,
) )
@ -236,13 +236,13 @@ describe(`Psbt`, () => {
if (f.shouldThrow) { if (f.shouldThrow) {
const psbtThatShouldThrow = Psbt.fromBase64(f.shouldThrow.psbt) const psbtThatShouldThrow = Psbt.fromBase64(f.shouldThrow.psbt)
assert.rejects(async () => { assert.rejects(async () => {
await psbtThatShouldThrow.signAsync( await psbtThatShouldThrow.signAllInputsAsync(
ECPair.fromWIF(f.shouldThrow.WIF), ECPair.fromWIF(f.shouldThrow.WIF),
f.shouldThrow.sighashTypes || undefined, f.shouldThrow.sighashTypes || undefined,
) )
}, new RegExp('No inputs were signed')) }, new RegExp('No inputs were signed'))
assert.rejects(async () => { assert.rejects(async () => {
await psbtThatShouldThrow.signAsync() await psbtThatShouldThrow.signAllInputsAsync()
}, new RegExp('Need Signer to sign input')) }, new RegExp('Need Signer to sign input'))
} }
}) })
@ -345,13 +345,13 @@ describe(`Psbt`, () => {
}) })
}) })
describe('signHDAsync', () => { describe('signAllInputsHDAsync', () => {
fixtures.signInputHD.checks.forEach(f => { fixtures.signInputHD.checks.forEach(f => {
it(f.description, async () => { it(f.description, async () => {
if (f.shouldSign) { if (f.shouldSign) {
const psbtThatShouldsign = Psbt.fromBase64(f.shouldSign.psbt) const psbtThatShouldsign = Psbt.fromBase64(f.shouldSign.psbt)
assert.doesNotReject(async () => { assert.doesNotReject(async () => {
await psbtThatShouldsign.signHDAsync( await psbtThatShouldsign.signAllInputsHDAsync(
bip32.fromBase58(f.shouldSign.xprv), bip32.fromBase58(f.shouldSign.xprv),
f.shouldSign.sighashTypes || undefined, f.shouldSign.sighashTypes || undefined,
) )
@ -361,13 +361,13 @@ describe(`Psbt`, () => {
if (f.shouldThrow) { if (f.shouldThrow) {
const psbtThatShouldThrow = Psbt.fromBase64(f.shouldThrow.psbt) const psbtThatShouldThrow = Psbt.fromBase64(f.shouldThrow.psbt)
assert.rejects(async () => { assert.rejects(async () => {
await psbtThatShouldThrow.signHDAsync( await psbtThatShouldThrow.signAllInputsHDAsync(
bip32.fromBase58(f.shouldThrow.xprv), bip32.fromBase58(f.shouldThrow.xprv),
f.shouldThrow.sighashTypes || undefined, f.shouldThrow.sighashTypes || undefined,
) )
}, new RegExp('No inputs were signed')) }, new RegExp('No inputs were signed'))
assert.rejects(async () => { assert.rejects(async () => {
await psbtThatShouldThrow.signHDAsync() await psbtThatShouldThrow.signAllInputsHDAsync()
}, new RegExp('Need HDSigner to sign input')) }, new RegExp('Need HDSigner to sign input'))
} }
}) })

View file

@ -58,7 +58,7 @@ const DEFAULT_OPTS: PsbtOpts = {
* data for updateOutput. * data for updateOutput.
* For a list of what attributes should be what types. Check the bip174 library. * For a list of what attributes should be what types. Check the bip174 library.
* Also, check the integration tests for some examples of usage. * Also, check the integration tests for some examples of usage.
* Signer: There are a few methods. signAllInputs and signAsync, which will search all input * Signer: There are a few methods. signAllInputs and signAllInputsAsync, which will search all input
* information for your pubkey or pubkeyhash, and only sign inputs where it finds * information for your pubkey or pubkeyhash, and only sign inputs where it finds
* your info. Or you can explicitly sign a specific input with signInput and * your info. Or you can explicitly sign a specific input with signInput and
* signInputAsync. For the async methods you can create a SignerAsync object * signInputAsync. For the async methods you can create a SignerAsync object
@ -351,7 +351,7 @@ export class Psbt {
return this; return this;
} }
signHDAsync( signAllInputsHDAsync(
hdKeyPair: HDSigner | HDSignerAsync, hdKeyPair: HDSigner | HDSignerAsync,
sighashTypes: number[] = [Transaction.SIGHASH_ALL], sighashTypes: number[] = [Transaction.SIGHASH_ALL],
): Promise<void> { ): Promise<void> {
@ -454,7 +454,7 @@ export class Psbt {
return this; return this;
} }
signAsync( signAllInputsAsync(
keyPair: Signer | SignerAsync, keyPair: Signer | SignerAsync,
sighashTypes: number[] = [Transaction.SIGHASH_ALL], sighashTypes: number[] = [Transaction.SIGHASH_ALL],
): Promise<void> { ): Promise<void> {

6
types/psbt.d.ts vendored
View file

@ -19,7 +19,7 @@ import { Transaction } from './transaction';
* data for updateOutput. * data for updateOutput.
* For a list of what attributes should be what types. Check the bip174 library. * For a list of what attributes should be what types. Check the bip174 library.
* Also, check the integration tests for some examples of usage. * Also, check the integration tests for some examples of usage.
* Signer: There are a few methods. signAllInputs and signAsync, which will search all input * Signer: There are a few methods. signAllInputs and signAllInputsAsync, which will search all input
* information for your pubkey or pubkeyhash, and only sign inputs where it finds * information for your pubkey or pubkeyhash, and only sign inputs where it finds
* your info. Or you can explicitly sign a specific input with signInput and * your info. Or you can explicitly sign a specific input with signInput and
* signInputAsync. For the async methods you can create a SignerAsync object * signInputAsync. For the async methods you can create a SignerAsync object
@ -62,11 +62,11 @@ export declare class Psbt {
validateSignaturesOfAllInputs(): boolean; validateSignaturesOfAllInputs(): boolean;
validateSignaturesOfInput(inputIndex: number, pubkey?: Buffer): boolean; validateSignaturesOfInput(inputIndex: number, pubkey?: Buffer): boolean;
signAllInputsHD(hdKeyPair: HDSigner, sighashTypes?: number[]): this; signAllInputsHD(hdKeyPair: HDSigner, sighashTypes?: number[]): this;
signHDAsync(hdKeyPair: HDSigner | HDSignerAsync, sighashTypes?: number[]): Promise<void>; signAllInputsHDAsync(hdKeyPair: HDSigner | HDSignerAsync, sighashTypes?: number[]): Promise<void>;
signInputHD(inputIndex: number, hdKeyPair: HDSigner, sighashTypes?: number[]): this; signInputHD(inputIndex: number, hdKeyPair: HDSigner, sighashTypes?: number[]): this;
signInputHDAsync(inputIndex: number, hdKeyPair: HDSigner | HDSignerAsync, sighashTypes?: number[]): Promise<void>; signInputHDAsync(inputIndex: number, hdKeyPair: HDSigner | HDSignerAsync, sighashTypes?: number[]): Promise<void>;
signAllInputs(keyPair: Signer, sighashTypes?: number[]): this; signAllInputs(keyPair: Signer, sighashTypes?: number[]): this;
signAsync(keyPair: Signer | SignerAsync, sighashTypes?: number[]): Promise<void>; signAllInputsAsync(keyPair: Signer | SignerAsync, sighashTypes?: number[]): Promise<void>;
signInput(inputIndex: number, keyPair: Signer, sighashTypes?: number[]): this; signInput(inputIndex: number, keyPair: Signer, sighashTypes?: number[]): this;
signInputAsync(inputIndex: number, keyPair: Signer | SignerAsync, sighashTypes?: number[]): Promise<void>; signInputAsync(inputIndex: number, keyPair: Signer | SignerAsync, sighashTypes?: number[]): Promise<void>;
toBuffer(): Buffer; toBuffer(): Buffer;