Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow SignatureTemplate signing of non-transaction messages #221

Open
mr-zwets opened this issue Oct 16, 2024 · 1 comment
Open

Allow SignatureTemplate signing of non-transaction messages #221

mr-zwets opened this issue Oct 16, 2024 · 1 comment
Labels
javascript-sdk Relates to the CashScript JavaScript SDK

Comments

@mr-zwets
Copy link
Member

There's a TODO for this in the code in SignatureTemplate.ts

  // TODO: Allow signing of non-transaction messages (i.e. don't add the hashtype)
  generateSignature(payload: Uint8Array, bchForkId?: boolean): Uint8Array {
    const signature = this.signatureAlgorithm === SignatureAlgorithm.SCHNORR
      ? secp256k1.signMessageHashSchnorr(this.privateKey, payload) as Uint8Array
      : secp256k1.signMessageHashDER(this.privateKey, payload) as Uint8Array;

    return Uint8Array.from([...signature, this.getHashType(bchForkId)]);
  }
@mr-zwets mr-zwets added the javascript-sdk Relates to the CashScript JavaScript SDK label Oct 16, 2024
@mr-zwets
Copy link
Member Author

mr-zwets commented Oct 30, 2024

Currently, without this CashScript option, devs need to use the libauth primitives for this, which requires manual conversions of the privateKey type into Uint8Array

import { secp256k1 } from '@bitauth/libauth';
import { sha256 } from '@cashscript/utils';

signMessage(message: Uint8Array, privateKey: Uint8Array): Uint8Array {
    const signature = secp256k1.signMessageHashSchnorr(privateKey, sha256(message));
    if (typeof signature === 'string') throw new Error();
    return signature;
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
javascript-sdk Relates to the CashScript JavaScript SDK
Projects
None yet
Development

No branches or pull requests

1 participant