Skip to content

Signing of P2SH transactions is not implemented except for P2SH Multisig #203

@bappelt

Description

@bappelt

The getSignatures() method on Transaction fails if the transaction being signed is a non-multisig P2SH transaction.

Expected Behavior

The transaction signature should be returned.

Current Behavior

The method throws Abstract Method Invocation: Trying to sign unsupported output type (only P2PKH and P2SH multisig inputs are supported) for input

Possible Solution

Steps to Reproduce (for bugs)

the following code attempts to sign a transaction spending from a trivial P2SH address with a locking script of

OP_5 OP_EQUAL <pubkey> OP_CHECKSIG

$ node
> const dashcore = require('@dashevo/dashcore-lib');
undefined
> tx = dashcore.Transaction('03000000018618449e1b1f090518ff2d2e7ec185af7688aca26b7c3a4a35db0c45117a05e30000000028005525558721032a90617b3d14645bb0db5acc83037ff4953ea7ecb2403430dd81375a2d69aeacacffffffff0118c69a3b000000001976a914efb38bcb860f3704cadab10947be89b7b24de70a88ac00000000')
<Transaction: 03000000018618449e1b1f090518ff2d2e7ec185af7688aca26b7c3a4a35db0c45117a05e30000000028005525558721032a90617b3d14645bb0db5acc83037ff4953ea7ecb2403430dd81375a2d69aeacacffffffff0118c69a3b000000001976a914efb38bcb860f3704cadab10947be89b7b24de70a88ac00000000>
> tx.getSignatures('cUstHm2KaHLXsqcVmq3eKkSs4258WCaHByvqMMmNVjrcFWCWWkCb')
Abstract Method Invocation: Trying to sign unsupported output type (only P2PKH and P2SH multisig inputs are supported) for input: {"prevTxId":"e3057a11450cdb354a3a7c6ba2ac8876af85c17e2e2dff1805091f1b9e441886","outputIndex":0,"sequenceNumber":4294967295,"script":"005525558721032a90617b3d14645bb0db5acc83037ff4953ea7ecb2403430dd81375a2d69aeacac","scriptString":"OP_0 OP_5 37 0x558721032a90617b3d14645bb0db5acc83037ff4953ea7ecb2403430dd81375a2d69aeacac"}
Error
   at Error.NodeError (dashcore-lib/lib/errors/index.js:23:41)
   at Input.getSignatures (dashcore-lib/lib/transaction/input/input.js:188:9)
   at forEachInput (dashcore-lib/lib/transaction/transaction.js:1168:18)
   at arrayEach (lodash/lodash.js:516:11)
   at Function.forEach (lodash/lodash.js:9368:14)
   at Transaction.getSignatures (dashcore-lib/lib/transaction/transaction.js:1167:5)
  > 

Context

P2SH transactions are needed to implement more sophisticated transactions like atomic swaps

Your Environment

  • Version used: 0.18.15

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions