CashScript / cashscript

⚖️ Easily write and interact with Bitcoin Cash smart contracts
https://cashscript.org
MIT License
115 stars 80 forks source link

Add `signatureAlgorithms` argument to `Sig` class #7

Closed cgcardona closed 2 years ago

cgcardona commented 5 years ago

Currently Sig defaults to Schnorr signatures which is causing a problem w/ MultiSig contracts. We need to default to ECDSA sigs and add an optional 3rd signatureAlgorithms argument to the Sig class. For example

export declare class Sig {
    keypair: ECPair;
    hashtype: number;
    sigtype: number;
    constructor(keypair: ECPair, hashtype: number, sigtype: number = 0x00);
}
cgcardona commented 5 years ago

Also can we make the hashtype argument optional and default to 0x01? That way there could be 3 states.

// default to 0x01 SIGHASH_ALL for hashtype and 0x00 ECDSA for sigtype
.spend(alicePK, new Sig(aliceKP))

// default to 0x00 ECDSA for sigtype
.spend(alicePK, new Sig(aliceKP, 0x01))

// explicit
.spend(alicePK, new Sig(aliceKP, 0x01, 0x00))
cgcardona commented 5 years ago

Let's pair program when you get to this so that we can confirm the hashtype and sigtype hex values are correct in my comment above.

Primarily we want to add a 3rd sigtype arg to the Sig constructor. We also want to make the 2nd and 3rd args optional. Ensure the 2nd arg defaults to SIGHASH_ALL and ensure the 3rd arg defaults to ECDSA

rkalis commented 2 years ago

Since multisigs now also support Schnorr signatures, I'd prefer being opinionated and only allowing Schnorr until there's a very strong use case for providing ECDSA support in SignatureTemplate.