function decode(buffer) {
  const hashType = tools.readUInt8(buffer, buffer.length - 1);
  if (!isDefinedHashType(hashType)) {
    throw new Error('Invalid hashType ' + hashType);
  }
  const decoded = bip66.decode(buffer.subarray(0, -1));
  const r = fromDER(decoded.r);
  const s = fromDER(decoded.s);
  const signature = tools.concat([r, s]);
  return { signature, hashType };
}
Decodes a buffer into a ScriptSignature object.
@param buffer - The buffer to decode.
@returns The decoded ScriptSignature object.
@throws Error if the hashType is invalid.